Welcome! Log In Create A New Profile

Advanced

[njs] Shell: fixed memory leak in script options.

Dmitry Volyntsev
August 31, 2021 09:18AM
details: https://hg.nginx.org/njs/rev/bf1464d84fd1
branches:
changeset: 1691:bf1464d84fd1
user: Dmitry Volyntsev <xeioex@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)
{
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Shell: fixed memory leak in script options.

Dmitry Volyntsev 275 August 31, 2021 09:18AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 110
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready