Skip to content

Commit 65b1e8b

Browse files
author
Jyri Sarha
committed
cmocka: pipeline: Fix memory leaks
Fix all memory leaks found from all pipeline tests when tests were run under Valgrind. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 865c461 commit 65b1e8b

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

test/cmocka/src/audio/pipeline/pipeline_connect_upstream.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static int setup(void **state)
2424

2525
static int teardown(void **state)
2626
{
27+
free_standard_connect_objects(*state);
2728
free(*state);
2829
return 0;
2930
}

test/cmocka/src/audio/pipeline/pipeline_connection_mocks.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct pipeline_connect_data *get_standard_connect_objects(void)
3030
struct pipeline_connect_data *pipeline_connect_data = calloc
3131
(sizeof(struct pipeline_connect_data), 1);
3232

33-
struct pipeline *pipe = calloc(sizeof(struct pipeline), 1);
33+
struct pipeline *pipe = &pipeline_connect_data->p;
3434

3535
pipe->frames_per_sched = 5;
3636
pipe->pipeline_id = PIPELINE_ID_SAME;
@@ -83,7 +83,14 @@ struct pipeline_connect_data *get_standard_connect_objects(void)
8383
comp_buffer_reset_source_list(buffer_2);
8484
pipeline_connect_data->b2 = buffer_2;
8585

86-
pipeline_connect_data->p = *pipe;
87-
8886
return pipeline_connect_data;
8987
}
88+
89+
void free_standard_connect_objects(struct pipeline_connect_data *data)
90+
{
91+
free(data->p.pipe_task);
92+
free(data->p.sched_comp);
93+
free(data->second);
94+
free(data->b1);
95+
free(data->b2);
96+
}

test/cmocka/src/audio/pipeline/pipeline_connection_mocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct pipeline_connect_data {
3232
};
3333

3434
struct pipeline_connect_data *get_standard_connect_objects(void);
35+
void free_standard_connect_objects(struct pipeline_connect_data *data);
3536

3637
void cleanup_test_data(struct pipeline_connect_data *data);
3738

test/cmocka/src/audio/pipeline/pipeline_free.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static int setup(void **state)
3636

3737
static int teardown(void **state)
3838
{
39+
free_standard_connect_objects(*state);
3940
free(*state);
4041
return 0;
4142
}

test/cmocka/src/audio/pipeline/pipeline_new.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ static void test_audio_pipeline_pipeline_new_creation(void **state)
5555

5656
/*Pipeline should have been created so pointer can't be null*/
5757
assert_non_null(result);
58+
59+
rfree(result->msg->tx_data);
60+
rfree(result->msg);
61+
rfree(result);
5862
}
5963

6064
int main(void)

0 commit comments

Comments
 (0)