Skip to content

Commit 0d2846f

Browse files
Add dlclose to prevent memory leak
A dynamically allocated pointer was not being properly cleaned up. This fixes the following Coverity issue: ``` lib/pkg_editor/src/zlib.c:119:1: Type: Resource leak (RESOURCE_LEAK) lib/pkg_editor/src/zlib.c:98:3: 1. path: Condition "zlib_interface.deflateInit_", taking false branch. lib/pkg_editor/src/zlib.c:101:3: 2. alloc_fn: Storage is returned from allocation function "zlib_load_library". lib/pkg_editor/src/zlib.c:90:3: 2.1. path: Condition "dlopen_handle", taking false branch. lib/pkg_editor/src/zlib.c:93:3: 2.2. alloc_fn: Storage is returned from allocation function "dlopen". lib/pkg_editor/src/zlib.c:93:3: 2.3. return_alloc_fn: Directly returning storage allocated by "dlopen". lib/pkg_editor/src/zlib.c:101:3: 3. var_assign: Assigning: "library" = storage returned from "zlib_load_library()". lib/pkg_editor/src/zlib.c:102:3: 4. path: Condition "library == NULL", taking false branch. lib/pkg_editor/src/zlib.c:110:3: 5. noescape: Resource "library" is not freed or pointed-to in "load_one_symbol". lib/pkg_editor/src/zlib.c:39:36: 5.1. noescape: "load_one_symbol(void *, char const *)" does not free or save its parameter "library". lib/pkg_editor/src/zlib.c:111:3: 6. noescape: Resource "library" is not freed or pointed-to in "load_one_symbol". lib/pkg_editor/src/zlib.c:39:36: 6.1. noescape: "load_one_symbol(void *, char const *)" does not free or save its parameter "library". lib/pkg_editor/src/zlib.c:112:3: 7. noescape: Resource "library" is not freed or pointed-to in "load_one_symbol". lib/pkg_editor/src/zlib.c:39:36: 7.1. noescape: "load_one_symbol(void *, char const *)" does not free or save its parameter "library". lib/pkg_editor/src/zlib.c:113:3: 8. noescape: Resource "library" is not freed or pointed-to in "load_one_symbol". lib/pkg_editor/src/zlib.c:39:36: 8.1. noescape: "load_one_symbol(void *, char const *)" does not free or save its parameter "library". lib/pkg_editor/src/zlib.c:114:3: 9. noescape: Resource "library" is not freed or pointed-to in "load_one_symbol". lib/pkg_editor/src/zlib.c:39:36: 9.1. noescape: "load_one_symbol(void *, char const *)" does not free or save its parameter "library". lib/pkg_editor/src/zlib.c:115:3: 10. noescape: Resource "library" is not freed or pointed-to in "load_one_symbol". lib/pkg_editor/src/zlib.c:39:36: 10.1. noescape: "load_one_symbol(void *, char const *)" does not free or save its parameter "library". lib/pkg_editor/src/zlib.c:119:1: 11. leaked_storage: Variable "library" going out of scope leaks the storage it points to. ```
1 parent b982e66 commit 0d2846f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/pkg_editor/src/zlib.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ static void zlib_load() {
116116
#ifdef _MSC_VER
117117
#pragma warning(pop)
118118
#endif
119+
#ifdef _WIN32
120+
FreeLibrary(library)
121+
#else
122+
dlclose(library);
123+
#endif
119124
}
120125

121126
int zlib_deflateInit(z_streamp strm, int level) {

0 commit comments

Comments
 (0)