Operating System - Linux
1756822 Members
2809 Online
108853 Solutions
New Discussion юеВ

Re: Purify reports std::vector memory leak

 
putagunta
New Member

Purify reports std::vector memory leak

Hi,

I've encountered problems with std::vector on HPUX. Purify reports memory leaks:
MLK: 1536 bytes leaked in 2 blocks
This memory was allocated from:
malloc [rtlib.o]
operator new(unsigned long) [libCsup_v2.2]
operator new(unsigned long) [rtlib.o]
std::vector>::_C_insert_aux(stoppert *,const stoppert &) [vector.cc:157]
std::vector>::push_back(const stoppert &) [vector:566]
Stopper::start() [Stopper.cpp:72]
static Connection::ClntMsgTh(void *) [Connection.cpp:8864]
__pthread_body [libpthread.1_pure_p3_c0_101232010_B1111_64_178192.a2s.HPUX.24291.tmp]
__pthread_start [libpthread.1_pure_p3_c0_101232010_B1111_64_178192.a2s.HPUX.24291.tmp]
Block of 768 bytes (2 times); last block at 0x80000001006b7e68

here is Stopper::start() function:
int Stopper::start()
{
stoppert start;
ftime( &start.time );
start.index = nextIndex++;
times.push_back(start);

return start.index;
}

times is a std:vector member of Stopper class.

Method start() is called from Connection::ClntMsgTh on a local variable:
Stopper mtx_time;
mtx_time.start();

Beside this one, purify reports leaks in many other calls of Stopper::start().

I'm using aCC: HP ANSI C++ B3910B A.03.70

Can anyone help me explaining this leaks?
3 REPLIES 3
Dennis Handly
Acclaimed Contributor

Re: Purify reports std::vector memory leak

>I'm using aCC: HP ANSI C++ B3910B A.03.70

I don't remember when I fixed the last bug in vector. For 11.11, you can patch up to A.03.77, PHSS_36087:
http://h21007.www2.hp.com/portal/site/dspp/template.PAGE/page.document/?ciid=2645dec4c7563110VgnVCM100000275d6e10RCRD#b11.11pa

>Can anyone help me explaining this leaks?

From your source, when you call push_back, you have to make a copy of "start" to add it to the vector. (If you are very unlucky, and the vector is full, every element must be copied but that shouldn't have leaks.)

Do you know the size of a stoppert? Is it 1536/2? If not, that size could be due to the vector reallocation. What's on vector.cc:157?

Where are you destroying Stopper::times?
putagunta
New Member

Re: Purify reports std::vector memory leak

>you can patch up to A.03.77, PHSS_36087:
I will try this, but it will take some time, because I am not the system administrator...

>Where are you destroying Stopper::times?
Stopper::times should be destroyed when the Stopper object exits the scop, i.e. when Connection::ClntMsgTh returns. I don't know if this is important, but this function is called every time from a different thread.

> Do you know the size of a stoppert?
Size of stoppert is 24.

>What's on vector.cc:157?
I would love to know this. In /opt/aCC/include_std/vector.cc:157 I found:
_C_end_of_storage = __start + __new_capacity;
I think I'm looking in the wrong file.
Dennis Handly
Acclaimed Contributor

Re: Purify reports std::vector memory leak

>I will try this, but it will take some time, because I am not the system administrator.

All you need is the two vector include files.

>Stopper::times should be destroyed when the Stopper object exits the scope

I assume it leaks after there? If before, it's a different issue.

>Size of stoppert is 24.

Then it looks like the whole vector is messed up?

>I would love to know this. In /opt/aCC/include_std/vector.cc:157 I found:
_C_end_of_storage = __start + __new_capacity;
I think I'm looking in the wrong file.

The last 3 versions have this same line but there could be 2 fixes missing.

JAGaf50801: vector::insert doesn't set last. Problem is with caller to copy_backward, not itself.
JAGad78735: can't change _C_end_of_storage if not reallocated.
JAGad87227: Fix for allocation of uninitialized storage