Fix potential Null pointer dereference in test-time.c (#1681)

* Fix potential Null pointer dereference in test-time.c

* add err path

* code review: free events before base

---------

Co-authored-by: icy17 <1061499390@qq.com>
This commit is contained in:
Cœur 2024-07-08 10:08:58 +02:00 committed by GitHub
parent 0bbaee6110
commit 2bc831c889
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -104,6 +104,9 @@ main(int argc, char **argv)
for (i = 0; i < NEVENT; i++) { for (i = 0; i < NEVENT; i++) {
ev[i] = evtimer_new(base, time_cb, event_self_cbarg()); ev[i] = evtimer_new(base, time_cb, event_self_cbarg());
if (ev[i] == NULL) {
goto err;
}
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = rand_int(50000); tv.tv_usec = rand_int(50000);
evtimer_add(ev[i], &tv); evtimer_add(ev[i], &tv);
@ -119,5 +122,14 @@ main(int argc, char **argv)
} else { } else {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
err:
for (i = 0; i < NEVENT; i++) {
if (ev[i])
event_free(ev[i]);
}
if (base)
event_base_free(base);
return EXIT_FAILURE;
} }