Commit cfeafeabad1d415e55afb0bdc0c7b2244b4bac10

Guillem Jover 2020-08-16T21:58:04

funopen: Fix memory leak in funopen_close() when closefn is NULL We need to free the cookiewrap even when the closefn method is NULL. Warned-by: gcc ASAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/src/funopen.c b/src/funopen.c
index 1e05c7e..1d908bc 100644
--- a/src/funopen.c
+++ b/src/funopen.c
@@ -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);