Dave's Brain

Browse - Programming Tips - In Borland C++ 5.02 std::string is leaking handles. How can I stop this?

Date: 2006Apr22
Language: C/C++
Keywords: correction
Product: Borland C++ 5.02

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); } }
Note 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-2017, 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.