@@ -617,28 +617,30 @@ static int read_ftrace_files(struct tracecmd_input *handle, const char *regex)
}
}
- if (read4(handle, &count) < 0)
- return -1;
+ ret = read4(handle, &count);
+ if (ret < 0)
+ goto out;
for (i = 0; i < count; i++) {
- if (read8(handle, &size) < 0)
- return -1;
+ ret = read8(handle, &size);
+ if (ret < 0)
+ goto out;
ret = read_ftrace_file(handle, size, print_all, ereg);
if (ret < 0)
- return -1;
+ goto out;
}
handle->event_files_start =
lseek64(handle->fd, 0, SEEK_CUR);
-
+ handle->file_state = TRACECMD_FILE_FTRACE_EVENTS;
+ ret = 0;
+out:
if (sreg) {
regfree(sreg);
regfree(ereg);
}
- handle->file_state = TRACECMD_FILE_FTRACE_EVENTS;
-
- return 0;
+ return ret;
}
static int read_event_files(struct tracecmd_input *handle, const char *regex)
Some error paths in read_ftrace_files() may lead to a memory leak. Improved the error handling of this internal function to avoid it. Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- lib/trace-cmd/trace-input.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)