]> git.ozlabs.org Git - ccan/blobdiff - ccan/io/poll.c
io: fix another leak path for always array.
[ccan] / ccan / io / poll.c
index 95b6103287d6335b0b84e4475a7b8469a2d33b54..17f9384587d92e39b37e199b0f05159bb899d112 100644 (file)
@@ -91,6 +91,10 @@ static void del_fd(struct fd *fd)
                pollfds = tal_free(pollfds);
                fds = NULL;
                max_fds = 0;
+               if (num_always == 0) {
+                       always = tal_free(always);
+                       max_always = 0;
+               }
        }
        num_fds--;
        fd->backend_info = -1;
@@ -137,6 +141,12 @@ static void remove_from_always(const struct io_plan *plan)
        if (pos != num_always-1)
                always[pos] = always[num_always-1];
        num_always--;
+
+       /* Only free if no fds left either. */
+       if (num_always == 0 && max_fds == 0) {
+               always = tal_free(always);
+               max_always = 0;
+       }
 }
 
 bool backend_new_always(struct io_plan *plan)