mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-28 12:30:58 +00:00
Fix #1539 - proper timer cleanup
This commit is contained in:
1 parent
b82953405d
commit
84480f4072
3 files changed
+11
No files matched your search
@@ -2809,6 +2809,7 @@ void mg_mgr_free(struct mg_mgr *mgr) {
|
||||
struct mg_connection *c;
|
||||
struct mg_timer *tmp, *t = mgr->timers;
|
||||
while (t != NULL) tmp = t->next, free(t), t = tmp;
|
||||
mgr->timers = NULL; // Important. Next call to poll won't touch timers
|
||||
for (c = mgr->conns; c != NULL; c = c->next) c->is_closing = 1;
|
||||
mg_mgr_poll(mgr, 0);
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
|
||||
@@ -230,6 +230,7 @@ void mg_mgr_free(struct mg_mgr *mgr) {
|
||||
struct mg_connection *c;
|
||||
struct mg_timer *tmp, *t = mgr->timers;
|
||||
while (t != NULL) tmp = t->next, free(t), t = tmp;
|
||||
mgr->timers = NULL; // Important. Next call to poll won't touch timers
|
||||
for (c = mgr->conns; c != NULL; c = c->next) c->is_closing = 1;
|
||||
mg_mgr_poll(mgr, 0);
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
|
||||
@@ -1262,6 +1262,15 @@ static void test_timer(void) {
|
||||
|
||||
mg_timer_free(&head, &t3);
|
||||
ASSERT(head == NULL);
|
||||
|
||||
// Test proper timer deallocation, see #1539
|
||||
{
|
||||
struct mg_mgr mgr;
|
||||
mg_mgr_init(&mgr);
|
||||
mg_timer_add(&mgr, 1, MG_TIMER_REPEAT, f1, NULL);
|
||||
mg_mgr_free(&mgr);
|
||||
ASSERT(mgr.conns == NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static bool sn(const char *fmt, ...) {
|
||||
|
||||
Reference in new issue
Block a user