@@ -191,11 +191,10 @@ static int busybox_progress_cb(void *arg)
device_handler_status_download(handler, procinfo,
percentage, size, suffix);
+ talloc_free(line);
return 0;
}
-
-
static void load_process_to_local_file(struct load_task *task,
const char **argv, int argv_local_idx)
{
@@ -97,7 +97,9 @@ static int process_read_stdout_once(struct process_info *procinfo, char **line)
}
if (line)
- *line = process->stdout_buf + process->stdout_len;
+ *line = talloc_strndup(procinfo,
+ process->stdout_buf + process->stdout_len,
+ rc + 1);
process->stdout_len += rc;
if (process->stdout_len == procinfo->stdout_buf_len - 1) {
@@ -268,6 +270,10 @@ static int sigchld_pipe_event(void *arg)
/* ensure we have all of the child's stdout */
process_read_stdout(procinfo);
+ /* clean up custom stdout handler if it still exists */
+ if (procinfo->stdout_waiter)
+ waiter_remove(procinfo->stdout_waiter);
+
if (process->exit_cb)
process->exit_cb(process);
If a line pointer is provided to process_read_stdout_once() it is set to the latest position in stdout_buf, however this is not guaranteed to be properly terminated. Instead allocate a copy of the new stdout_buf portion which is safely terminated by talloc_strndup(). The caller must free this string. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com> --- discover/paths.c | 3 +-- lib/process/process.c | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-)