[Gc] Possible bug: GC_realloc
bruce at hoult.org
Sat Feb 16 00:14:49 PST 2013
std::list does not use memory allocated by the GC so it will not be
traced by the GC. Therefore anything which is pointed to only by the
std::list will be regarded by the GC as being unreachable, and will
therefore be collected, leaving an invalid pointer in the list.
On Sat, Feb 16, 2013 at 6:59 AM, Bryan Ischo <bji at tivo.com> wrote:
> Hi there. I believe there is a bug in libgc surrounding GC_realloc. I
> have attached a simple program which demonstrates this problem. At
> first I thought the problem was with GC_realloc mixed with
> GC_register_finalizer, but when I added in code to turn off use of
> GC_register_finalizer, I still get the bug. So I now think that
> GC_register_finalizer is a red herring and has nothing to do with the
> As far as I can tell, the error occurs when an attempt is made to call
> GC_realloc on memory that was already GC_realloc'd; i.e.
> void *a = GC_malloc(...);
> void *b = GC_realloc(a, ...);
> void *c = GC_realloc(b, ...);
> It is only when the third GC_realloc is done that the error occurs. When
> GC_DEBUG is enabled, the error printed is this:
> Attempt to reallocate invalid pointer 0x7f9ca0
> When GC_DEBUG is not enabled, the result is a segmentation fault.
> Note that this does not occur on every such realloc sequence (a trivial
> program doing just the three lines above does not experience the
> problem), it does seem to require some nontrivial sequence of allocs and
> reallocs to occur.
> For my operating system (Linux 3.6.4, x86_64) and version of libgc
> (7.2), the test program fails after the 290th iteration; I will attach
> my sample output as well.
> (I a running with NO_FINALIZER set because I don't believe that
> finalizers actually have any bearing on the problem after all)
> Here is how I compile the program:
> g++ -o gcbug gcbug.cpp -lgc
> Here is how I run the program:
> NO_FINALIZER=1 gcbug
> This email and any attachments may contain confidential and privileged
> material for the sole use of the intended recipient. Any review, copying, or
> distribution of this email (or any attachments) by others is prohibited. If
> you are not the intended recipient, please contact the sender immediately
> and permanently delete this email and any attachments. No employee or agent
> of TiVo Inc. is authorized to conclude any binding agreement on behalf of
> TiVo Inc. by email. Binding agreements with TiVo Inc. may only be made by a
> signed written agreement.
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
> Gc mailing list
> Gc at linux.hpl.hp.com
More information about the Gc