Reads a wrong trace.dat file, the read_cpu_data() function returns a failure, it will cause memory double free. we should init kbuf back to NULL after free kbuf. and if kbuffer_alloc() fail, do not need to free any more. Signed-off-by: Ditang Chen <chendt.fnst@xxxxxxxxxxxxxx> --- trace-input.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/trace-input.c b/trace-input.c index 6eef168..7bebbfe 100644 --- a/trace-input.c +++ b/trace-input.c @@ -1841,7 +1841,7 @@ static int read_cpu_data(struct tracecmd_input *handle) handle->cpu_data[cpu].kbuf = kbuffer_alloc(long_size, endian); if (!handle->cpu_data[cpu].kbuf) - goto out_free; + return -1; if (pevent->old_format) kbuffer_set_old_format(handle->cpu_data[cpu].kbuf); @@ -1870,6 +1870,7 @@ static int read_cpu_data(struct tracecmd_input *handle) for ( ; cpu >= 0; cpu--) { free_page(handle, cpu); kbuffer_free(handle->cpu_data[cpu].kbuf); + handle->cpu_data[cpu].kbuf = NULL; } return -1; @@ -2209,7 +2210,7 @@ void tracecmd_close(struct tracecmd_input *handle) /* The tracecmd_peek_data may have cached a record */ free_next(handle, cpu); free_page(handle, cpu); - if (handle->cpu_data) { + if (handle->cpu_data && handle->cpu_data[cpu].kbuf) { kbuffer_free(handle->cpu_data[cpu].kbuf); if (!list_empty(&handle->cpu_data[cpu].pages)) -- 1.8.2.1 -- To unsubscribe from this list: send the line "unsubscribe linux-trace-users" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html