Юрий Соколов
2015-07-13 11:12:40 UTC
Using libgc from Ubuntu 15.04 (7.2b-6.4) this simple code leaks:
#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;
} }
stackoverflow question
http://stackoverflow.com/questions/31380641/libgc-why-this-code-leaks
#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;
} }
stackoverflow question
http://stackoverflow.com/questions/31380641/libgc-why-this-code-leaks