help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: hash_set core dump on memory free


From: Paul Pluzhnikov
Subject: Re: hash_set core dump on memory free
Date: Sat, 04 Nov 2006 19:41:33 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux)

"Rakesh" <nikki.haw@gmail.com> writes:

[Inapproptiate newsgroups trimmed]

> What is wrong this implementation?

Not much. A better question is: what's wrong with your code?

>   for (Iter1 = AddedPhrases.begin(); Iter1 != AddedPhrases.end(); Iter1++)
>   {
>          temp = *Iter1;
>          free(temp);
>   }

You are invalidating the storage of a container that you are
iterating over, but iteration *needs* access to that storage.

This (naturally) results in reading dangling memory (run your program
under valgrind to see how exactly that read dangling happens).

> Deleting:apple:5
> Deleting:absent:6
> *** glibc detected *** ./a.out: double free or corruption (!prev):

But I fail to see how this could result in a double-free, or in
heap corruption.

Regardless, you must fix your code (e.g. by using strings instead of
'char*' pointers).

Cheers,
-- 
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]