]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
funopen: Fix memory leak in funopen_close() when closefn is NULL
authorGuillem Jover <guillem@hadrons.org>
Sun, 16 Aug 2020 19:58:04 +0000 (21:58 +0200)
committerGuillem Jover <guillem@hadrons.org>
Mon, 21 Dec 2020 16:44:26 +0000 (17:44 +0100)
We need to free the cookiewrap even when the closefn method is NULL.

Warned-by: gcc ASAN
src/funopen.c

index 1e05c7e75188b14974d30ce8f6b74d67d44541b7..1d908bcb39d20a31b0b46817365cac54fca7479d 100644 (file)
@@ -87,10 +87,10 @@ funopen_close(void *cookie)
        struct funopen_cookie *cookiewrap = cookie;
        int rc;
 
-       if (cookiewrap->closefn == NULL)
-               return 0;
-
-       rc = cookiewrap->closefn(cookiewrap->orig_cookie);
+       if (cookiewrap->closefn)
+               rc = cookiewrap->closefn(cookiewrap->orig_cookie);
+       else
+               rc = 0;
 
        free(cookiewrap);