Fix greenbean example

The memory leak detector was crashing. When using gc() you shouldn't use
the CheckForMemoryLeaks() function from inside the same function, due to
how it runs the atexit handlers.
This commit is contained in:
Justine Tunney 2024-07-07 15:55:55 -07:00
parent f590e96abd
commit 3f2a1b696e
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
4 changed files with 8 additions and 30 deletions

View file

@ -33,28 +33,6 @@ forceinline bool PointerNotOwnedByParentStackFrame(struct StackFrame *frame,
((intptr_t)ptr < (intptr_t)parent));
}
static void TeardownGc(void) {
struct Garbages *g;
struct CosmoTib *t;
if (__tls_enabled) {
t = __get_tls();
if ((g = t->tib_garbages)) {
// exit() currently doesn't use gclongjmp() like pthread_exit()
// so we need to run the deferred functions manually.
while (g->i) {
--g->i;
((void (*)(intptr_t))g->p[g->i].fn)(g->p[g->i].arg);
}
free(g->p);
free(g);
}
}
}
__attribute__((__constructor__(51))) static textstartup void InitGc(void) {
atexit(TeardownGc);
}
// add item to garbage shadow stack.
// then rewrite caller's return address on stack.
static void DeferFunction(struct StackFrame *frame, void *fn, void *arg) {