#792268 libgc1c2: memory leak with simple code

Package:
libgc1c2
Source:
libgc
Submitter:
Юрий Соколов
Date:
2025-07-28 19:17:03 UTC
Severity:
important
#792268#5
Date:
2015-07-13 12:24:37 UTC
From:
To:
Dear Christoph Egger
<https://bugs.debian.org/cgi-bin/pkgreport.cgi?maint=christoph%40debian.org>
,

I've tried to test performance of libgc with simple code.

I've made a simple program that creates a single linked list, but
remembers only last item.

It leaks memory when linked with bundled libgc, and do not leaks when
linked with libgc compilled from source.

Note: while i'm using Ubuntu, i've already asked my friend to test it
on Debian stable, and he confirms bug exists. That is why I post bug
report to Debian.

Source code:

    #include <gc.h>

    struct list {
        struct list* next;
    };

    int main() {
        GC_INIT();
        struct list *last = NULL;
        for (;;) {
            struct list* nuo = GC_MALLOC(sizeof(struct list));
            nuo->next = NULL;
            // if next line is commented, then no leakage
            if (last) last->next = nuo;
            last = nuo;
        }
    }