]> git.kaiwu.me - njs.git/commitdiff
Shell: fixed memory leak in script options.
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 31 Aug 2021 13:16:42 +0000 (13:16 +0000)
committerDmitry Volyntsev <xeioex@nginx.com>
Tue, 31 Aug 2021 13:16:42 +0000 (13:16 +0000)
src/njs_shell.c

index 12ddb10869f60a9de8746bc1227f2d5f038fce7b..dd9e77c847ed31b16cbdd6e525c3fdc19c78989e 100644 (file)
@@ -93,7 +93,8 @@ static njs_int_t njs_process_script(njs_opts_t *opts,
 
 #ifndef NJS_FUZZER_TARGET
 
-static njs_int_t njs_get_options(njs_opts_t *opts, int argc, char **argv);
+static njs_int_t njs_options_parse(njs_opts_t *opts, int argc, char **argv);
+static void njs_options_free(njs_opts_t *opts);
 static njs_int_t njs_process_file(njs_opts_t *opts, njs_vm_opt_t *vm_options);
 static njs_int_t njs_interactive_shell(njs_opts_t *opts,
     njs_vm_opt_t *vm_options);
@@ -223,7 +224,7 @@ main(int argc, char **argv)
     njs_memzero(&opts, sizeof(njs_opts_t));
     opts.interactive = 1;
 
-    ret = njs_get_options(&opts, argc, argv);
+    ret = njs_options_parse(&opts, argc, argv);
     if (ret != NJS_OK) {
         ret = (ret == NJS_DONE) ? NJS_OK : NJS_ERROR;
         goto done;
@@ -294,16 +295,14 @@ main(int argc, char **argv)
 
 done:
 
-    if (opts.paths != NULL) {
-        free(opts.paths);
-    }
+    njs_options_free(&opts);
 
     return (ret == NJS_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
 
 static njs_int_t
-njs_get_options(njs_opts_t *opts, int argc, char **argv)
+njs_options_parse(njs_opts_t *opts, int argc, char **argv)
 {
     char        *p, **paths;
     njs_int_t   i, ret;
@@ -461,6 +460,19 @@ done:
 }
 
 
+static void
+njs_options_free(njs_opts_t *opts)
+{
+    if (opts->paths != NULL) {
+        free(opts->paths);
+    }
+
+    if (opts->argv != NULL) {
+        free(opts->argv);
+    }
+}
+
+
 static njs_int_t
 njs_process_file(njs_opts_t *opts, njs_vm_opt_t *vm_options)
 {