]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
examples/hiperfifo.c: check event_initialized before delete
authorJochem Broekhoff <jochembroekhoff@users.noreply.github.com>
Fri, 9 Apr 2021 09:03:30 +0000 (11:03 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 9 Apr 2021 09:44:21 +0000 (11:44 +0200)
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

docs/examples/hiperfifo.c

index 2ca625183527883b86f6a57a2c933026e0be7437..b22f1a71c5b910bc9a636eb7f78007cf3b23d79d 100644 (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);
 }