examples/hiperfifo.c: check event_initialized before delete

If event_del is called with the event struct (still) zeroed out, a
segmentation fault may occur.  event_initialized checks whether the
event struct is nonzero.

Closes #6876
This commit is contained in:
Jochem Broekhoff 2021-04-09 11:03:30 +02:00 committed by Daniel Stenberg
parent 9c1e1a6105
commit 255bdfe65c
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
1 changed files with 6 additions and 2 deletions

View File

@ -234,7 +234,9 @@ static void timer_cb(int fd, short kind, void *userp)
static void remsock(SockInfo *f)
{
if(f) {
event_del(&f->ev);
if(event_initialized(&f->ev)) {
event_del(&f->ev);
}
free(f);
}
}
@ -252,7 +254,9 @@ static void setsock(SockInfo *f, curl_socket_t s, CURL *e, int act,
f->sockfd = s;
f->action = act;
f->easy = e;
event_del(&f->ev);
if(event_initialized(&f->ev)) {
event_del(&f->ev);
}
event_assign(&f->ev, g->evbase, f->sockfd, kind, event_cb, g);
event_add(&f->ev, NULL);
}