orangeduck / tgc

A Tiny Garbage Collector for C
Other
968 stars 64 forks source link

What if `p->dtor` is `NULL` in `tgc_free`? #5

Closed loggerhead closed 8 years ago

loggerhead commented 8 years ago

I think the logic of tgc_free should changed to:

void tgc_free(tgc_t *gc, void *ptr) {
    tgc_ptr_t *p  = tgc_get_ptr(gc, ptr);
    if (p) {
        if (p->dtor) {
            p->dtor(ptr);
        }
        free(ptr);
        tgc_rem(gc, ptr);
    }
}
orangeduck commented 8 years ago

Yes I think you're correct, good catch.

orangeduck commented 8 years ago

fixed in 88c13cb3b06f461dc5087d4e532d42dc252b3756