Dave's Brain

Browse - programming tips - borland 5 std string handle leak fix

Date: 2006Apr22
Language: C/C++

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.
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2010, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.