diff --git a/src/exec.cc b/src/exec.cc index 80a93c9b..323f2df4 100644 --- a/src/exec.cc +++ b/src/exec.cc @@ -245,8 +245,8 @@ void fill_p(const char *buffer, struct text_object *obj, char *p, void scan_exec_arg(struct text_object *obj, const char *arg, unsigned int execflag) { const char *cmd = arg; + char *orig_cmd = nullptr; 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) { @@ -263,7 +263,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; + orig_cmd = (char *)cmd; } /* parse any special options for the graphical exec types */ @@ -289,9 +289,7 @@ 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); - } + free_and_zero(orig_cmd); } /**