mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
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:
parent
0bbaee6110
commit
2bc831c889
@ -104,6 +104,9 @@ main(int argc, char **argv)
|
||||
|
||||
for (i = 0; i < NEVENT; i++) {
|
||||
ev[i] = evtimer_new(base, time_cb, event_self_cbarg());
|
||||
if (ev[i] == NULL) {
|
||||
goto err;
|
||||
}
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = rand_int(50000);
|
||||
evtimer_add(ev[i], &tv);
|
||||
@ -119,5 +122,14 @@ main(int argc, char **argv)
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user