Skip to content

Commit

Permalink
[core][no_upstream] add sanity checks to ogs_timer alloc/free (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
spencersevilla committed Jan 24, 2024
1 parent 3b2c6ed commit 463d8bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/core/ogs-timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ ogs_timer_t *ogs_timer_add(
memset(timer, 0, sizeof *timer);
timer->cb = cb;
timer->data = data;

timer->assigned = true;
timer->manager = manager;

return timer;
Expand All @@ -112,6 +112,13 @@ void ogs_timer_delete_debug(ogs_timer_t *timer, const char *file_line)
ogs_assert_if_reached();
}

// we can recover from double-free by just returning here
if (!timer->assigned) {
ogs_error("ogs_timer_delete double free");
return;
}
timer->assigned = false;

ogs_timer_stop(timer);

ogs_pool_free(&manager->pool, timer);
Expand Down
2 changes: 2 additions & 0 deletions lib/core/ogs-timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ typedef struct ogs_timer_s {
ogs_timer_mgr_t *manager;
bool running;
ogs_time_t timeout;

bool assigned;
} ogs_timer_t;

ogs_timer_mgr_t *ogs_timer_mgr_create(unsigned int capacity);
Expand Down

0 comments on commit 463d8bc

Please sign in to comment.