[njs] Shell: fixed memory leak in script options.
Dmitry Volyntsev
xeioex at nginx.com
Tue Aug 31 13:17:39 UTC 2021
details: https://hg.nginx.org/njs/rev/bf1464d84fd1
branches:
changeset: 1691:bf1464d84fd1
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Tue Aug 31 13:16:42 2021 +0000
description:
Shell: fixed memory leak in script options.
diffstat:
src/njs_shell.c | 24 ++++++++++++++++++------
1 files changed, 18 insertions(+), 6 deletions(-)
diffs (61 lines):
diff -r c9d24865a9e0 -r bf1464d84fd1 src/njs_shell.c
--- a/src/njs_shell.c Tue Aug 31 13:16:32 2021 +0000
+++ b/src/njs_shell.c Tue Aug 31 13:16:42 2021 +0000
@@ -93,7 +93,8 @@ static njs_int_t njs_process_script(njs_
#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)
{
More information about the nginx-devel
mailing list