From bbaa0e9ac8d8024245c2dde676ed4b6376f8300e Mon Sep 17 00:00:00 2001 From: lasers Date: Mon, 13 Aug 2018 13:55:31 -0500 Subject: [PATCH] exec.cc: Free malloced pointer after use in scan_exec_arg() (#607) --- src/exec.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/exec.cc b/src/exec.cc index 9ba47408..bc6bf47b 100644 --- a/src/exec.cc +++ b/src/exec.cc @@ -245,6 +245,7 @@ void scan_exec_arg(struct text_object *obj, const char *arg, unsigned int execflag) { const char *cmd = arg; struct execi_data *ed; + unsigned int free_cmd = 0; /* in case we have an execi object, we need to parse out the interval */ if ((execflag & EF_EXECI) != 0u) { @@ -261,6 +262,7 @@ void scan_exec_arg(struct text_object *obj, const char *arg, /* set cmd to everything after the interval */ cmd = strndup(arg + n, text_buffer_size.get(*state)); + free_cmd = 1; } /* parse any special options for the graphical exec types */ @@ -286,6 +288,9 @@ void scan_exec_arg(struct text_object *obj, const char *arg, ed->cmd = strndup(cmd != nullptr ? cmd : "", text_buffer_size.get(*state)); obj->data.opaque = ed; } + if (cmd != nullptr && 1 == free_cmd) { + free((char *)cmd); + } } /**