]> granicus.if.org Git - libevent/commitdiff
Correctly free selectop fields when select_resize fails in select_init
authorNick Mathewson <nickm@torproject.org>
Thu, 13 Jan 2011 01:28:47 +0000 (20:28 -0500)
committerNick Mathewson <nickm@torproject.org>
Thu, 13 Jan 2011 01:28:47 +0000 (20:28 -0500)
select.c

index 8327518eb4da4b1137a4d19c767e7495929d43c7..9495631813a03a5593a19ced55cace2a028f4c7c 100644 (file)
--- a/select.c
+++ b/select.c
@@ -90,6 +90,7 @@ const struct eventop selectops = {
 };
 
 static int select_resize(struct selectop *sop, int fdsz);
+static void select_free_selectop(struct selectop *sop);
 
 static void *
 select_init(struct event_base *base)
@@ -100,9 +101,7 @@ select_init(struct event_base *base)
                return (NULL);
 
        if (select_resize(sop, howmany(32 + 1, NFDBITS)*sizeof(fd_mask))) {
-               /* select_resize might have left this around. */
-               if (sop->event_readset_in)
-                       mm_free(sop->event_readset_in);
+               select_free_selectop(sop);
                return (NULL);
        }
 
@@ -306,11 +305,8 @@ select_del(struct event_base *base, int fd, short old, short events, void *p)
 }
 
 static void
-select_dealloc(struct event_base *base)
+select_free_selectop(struct selectop *sop)
 {
-       struct selectop *sop = base->evbase;
-
-       evsig_dealloc(base);
        if (sop->event_readset_in)
                mm_free(sop->event_readset_in);
        if (sop->event_writeset_in)
@@ -323,3 +319,11 @@ select_dealloc(struct event_base *base)
        memset(sop, 0, sizeof(struct selectop));
        mm_free(sop);
 }
+
+static void
+select_dealloc(struct event_base *base)
+{
+       evsig_dealloc(base);
+
+       select_free_selectop(base->evbase);
+}