SGI STL STLPort deque memory leak (not related to optimized allocator) 
Author Message
 SGI STL STLPort deque memory leak (not related to optimized allocator)

Hi Everybody,

I found a memory leak in the deque template in SGI STL/STLPort recently.
It's unrelated to the optimized default allocator.  Haven't found any
mention
of this on Deja/Google groups.  So I'll post a note here because someone
is bound to come looking...

The behaviour of this bug is that anything you erase from the front of the
deque gets leaked.  Have a look at SGI STL v3.3, stl_deque.h, in
deque<>::erase(iterator, iterator).

Lines 1013-1019 read as follows:
    if (__elems_before < difference_type((this->size() - __n) / 2)) {
        copy_backward(_M_start, __first, __last);
        iterator __new_start = _M_start + __n;
        destroy(_M_start, __new_start);
        _M_destroy_nodes(__new_start._M_node, _M_start._M_node);
        _M_start = __new_start;
    }

Because __new_start comes after _M_start, line 1017 never destroys
any of the nodes.  The fix is obvious:

    _M_destry_nodes(_M_start._M_node, __new_start._M_node);

You'll see the same problem in STLPort 4.5 and likely previous versions
of SGI STL/STLPort.

Anyway, this fixed it for me, and deque now works perfectly as far as
I'm concerned.  Good luck!

Qin Liu


      [ about comp.lang.c++.moderated. First time posters: do this! ]



Sat, 01 May 2004 18:50:38 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Custom Allocator class for SGI STL

2. Porting from SGI's STL to STLPort 4.5.1 in VC6

3. deque memory leak

4. Memory leak in deque of VC 6.0 SP3

5. Memory leak in deque of VC 6.0 SP3

6. deque memory leak

7. STLPort, MFC and memory leak report

8. STLPort, MFC and memory leak report

9. STL, std::allocator and memory mapped files

10. stlport memory leaks when closing application

11. STLPort, MFC and memory leak report

12. STL custom allocator using memory mapped file

 

 
Powered by phpBB® Forum Software