[Gc] Garbage collector bug
Thu, 9 Jan 2003 12:27:14 +1100
On 08-Jan-2003, Nadel, Alexander <ANadel@ndsisrael.com> wrote:
> I have written a program in ANSI C that is supposed to work under any
> platform and for any C compiler. After checking that it does work under
> Windows and various UNIX system, I released it. Than I got a report that it
> doesn't work properly when compiled using gcc, which uses built-in garbage
First principle of bug reports: always say which OS you are using,
and exactly which version of all of the programs involved is being used
(e.g. which version of gcc, and which version of the GC, if there is a
> After some investigation, I understood that there happened the following
> problem :
> At some stage of program's running there where 2 memory blocks A and B, A
> holding pointers to B.
> Than A was reallocated : A = realloc(A,...).
> A was copied to another location holding the same data and the same pointers
> to B.
> But, the data in B have changed! It shouldn't have happened and it doesn't
> happen with other compilers.
Probably there is a bug in your program. As Hans explained, gcc doesn't
link C programs with a garbage collector by default. So it seems very
unlikely that there is any garbage collector involved here.
The fact that your program works on some systems doesn't mean that it
is bug-free; it could be working just by coincidence. For example,
maybe your program overwrites memory at some random location, and on
some systems this memory is not important, and on some systems it is.
You may have corrupted your heap, in which case realloc() might not work
properly. Or maybe you just freed the data in B, and on some systems
realloc() doesn't reuse that freed space immediately, and on other
systems it does.
Fergus Henderson <email@example.com> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <https://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.