Dave's Brain

Browse - programming tips - borland 5 correction

Date: 2006Apr22

Q. In Borland C++ 5.02 std::string is leaking handles.  How can I stop this?

A. Its not freeing up the string's mutex when the string is freed.
Make these changes in C:\BC5\include ...

In stdmutex.h, rename destructor of ~RWSTDMutex() to destroy()
and make a new ~RWSTDMutex() which just calls destroy.

In string.h line 1253, add a call to mutex_.destroy() ...

template <class charT, class traits, class Allocator >
inline void string_ref<charT, traits, Allocator>::unLink(Allocator& alloc)
{
    if (removeReference() == 0)
    {
// begin dave fix
#ifdef RWSTD_MULTI_THREAD
		mutex_.destroy();
#endif
// end dave fix
		alloc.deallocate((charT*)this);
    }
}

Not that even after this fix, a mutex is allocated for each std::string
which seems excessive to me.

Add a comment

Sign in to add a comment
Copyright © 2008, dave - Code on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License.