Commit ae4d9f52 authored by Mathieu Poirier's avatar Mathieu Poirier Committed by Arnaldo Carvalho de Melo

perf cs-etm: Fix memory leak in error path

Memory allocated for variable 't_params' isn't released properly in the
error path of function cs_etm_queue *cs_etm__alloc_queue() and
cs_etm__dump_event(), something this patch addresses.
Signed-off-by: default avatarMathieu Poirier <mathieu.poirier@linaro.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Suzuki K Poulouse <suzuki.poulose@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: http://lkml.kernel.org/r/20190212171618.25355-6-mathieu.poirier@linaro.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 65963e5b
...@@ -175,6 +175,10 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm, ...@@ -175,6 +175,10 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm,
/* Use metadata to fill in trace parameters for trace decoder */ /* Use metadata to fill in trace parameters for trace decoder */
t_params = zalloc(sizeof(*t_params) * etm->num_cpu); t_params = zalloc(sizeof(*t_params) * etm->num_cpu);
if (!t_params)
return;
for (i = 0; i < etm->num_cpu; i++) { for (i = 0; i < etm->num_cpu; i++) {
if (etm->metadata[i][CS_ETM_MAGIC] == __perf_cs_etmv3_magic) { if (etm->metadata[i][CS_ETM_MAGIC] == __perf_cs_etmv3_magic) {
u32 etmidr = etm->metadata[i][CS_ETM_ETMIDR]; u32 etmidr = etm->metadata[i][CS_ETM_ETMIDR];
...@@ -206,14 +210,12 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm, ...@@ -206,14 +210,12 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm,
/* Set decoder parameters to simply print the trace packets */ /* Set decoder parameters to simply print the trace packets */
if (cs_etm__init_decoder_params(&d_params, NULL, if (cs_etm__init_decoder_params(&d_params, NULL,
CS_ETM_OPERATION_PRINT)) CS_ETM_OPERATION_PRINT))
return; goto out_free;
decoder = cs_etm_decoder__new(etm->num_cpu, &d_params, t_params); decoder = cs_etm_decoder__new(etm->num_cpu, &d_params, t_params);
zfree(&t_params);
if (!decoder) if (!decoder)
return; goto out_free;
do { do {
size_t consumed; size_t consumed;
...@@ -228,6 +230,9 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm, ...@@ -228,6 +230,9 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm,
} while (buffer_used < buffer->size); } while (buffer_used < buffer->size);
cs_etm_decoder__free(decoder); cs_etm_decoder__free(decoder);
out_free:
zfree(&t_params);
} }
static int cs_etm__flush_events(struct perf_session *session, static int cs_etm__flush_events(struct perf_session *session,
...@@ -379,7 +384,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, ...@@ -379,7 +384,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm,
{ {
int i; int i;
struct cs_etm_decoder_params d_params; struct cs_etm_decoder_params d_params;
struct cs_etm_trace_params *t_params; struct cs_etm_trace_params *t_params = NULL;
struct cs_etm_queue *etmq; struct cs_etm_queue *etmq;
size_t szp = sizeof(struct cs_etm_packet); size_t szp = sizeof(struct cs_etm_packet);
...@@ -461,8 +466,6 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, ...@@ -461,8 +466,6 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm,
etmq->decoder = cs_etm_decoder__new(etm->num_cpu, &d_params, t_params); etmq->decoder = cs_etm_decoder__new(etm->num_cpu, &d_params, t_params);
zfree(&t_params);
if (!etmq->decoder) if (!etmq->decoder)
goto out_free; goto out_free;
...@@ -475,6 +478,8 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, ...@@ -475,6 +478,8 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm,
cs_etm__mem_access)) cs_etm__mem_access))
goto out_free_decoder; goto out_free_decoder;
zfree(&t_params);
etmq->offset = 0; etmq->offset = 0;
etmq->period_instructions = 0; etmq->period_instructions = 0;
...@@ -483,6 +488,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, ...@@ -483,6 +488,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm,
out_free_decoder: out_free_decoder:
cs_etm_decoder__free(etmq->decoder); cs_etm_decoder__free(etmq->decoder);
out_free: out_free:
zfree(&t_params);
zfree(&etmq->event_buf); zfree(&etmq->event_buf);
zfree(&etmq->last_branch); zfree(&etmq->last_branch);
zfree(&etmq->last_branch_rb); zfree(&etmq->last_branch_rb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment