diff options
author | mugitya03 <mugitya233@outlook.com> | 2025-03-09 16:47:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-09 21:47:27 +0100 |
commit | c727be4df96d2f01af2fe1905c567c5a16fe1ae8 (patch) | |
tree | f27aae310aa827d4add38131a8872426170adad3 /docs/code/plugin | |
parent | 98a4bab92a1d114b22445a413a0dd991841ade61 (diff) | |
download | libuv-c727be4df96d2f01af2fe1905c567c5a16fe1ae8.tar.gz libuv-c727be4df96d2f01af2fe1905c567c5a16fe1ae8.zip |
doc: free lib pointer before function return (#4720)
In function main, the pointer lib allocated at line 7 is passed as an
argument to functions uv_dlopen at line 10, uv_dlerror at lines 11 and
17, and uv_dlsym at line 16, but it is never freed before the function
returns at line 24. This results in a memory leak bug.
Diffstat (limited to 'docs/code/plugin')
-rw-r--r-- | docs/code/plugin/main.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/docs/code/plugin/main.c b/docs/code/plugin/main.c index 06e581e6..01335bbc 100644 --- a/docs/code/plugin/main.c +++ b/docs/code/plugin/main.c @@ -18,22 +18,21 @@ int main(int argc, char **argv) { return 0; } - uv_lib_t *lib = (uv_lib_t*) malloc(sizeof(uv_lib_t)); + uv_lib_t lib; while (--argc) { fprintf(stderr, "Loading %s\n", argv[argc]); - if (uv_dlopen(argv[argc], lib)) { - fprintf(stderr, "Error: %s\n", uv_dlerror(lib)); + if (uv_dlopen(argv[argc], &lib)) { + fprintf(stderr, "Error: %s\n", uv_dlerror(&lib)); continue; } init_plugin_function init_plugin; - if (uv_dlsym(lib, "initialize", (void **) &init_plugin)) { - fprintf(stderr, "dlsym error: %s\n", uv_dlerror(lib)); + if (uv_dlsym(&lib, "initialize", (void **) &init_plugin)) { + fprintf(stderr, "dlsym error: %s\n", uv_dlerror(&lib)); continue; } init_plugin(); } - return 0; } |