From 692a5cc958012f4d754ab20fcec36e35e1d3ebdd Mon Sep 17 00:00:00 2001 From: Alexy Joseph Date: Wed, 10 Feb 2016 12:01:44 -0800 Subject: hal: Fix potential memory leaks in HAL Fix potential memory leaks in HAL Change-Id: Ifd491cc185a7d1afa647f03639e57d1685d18803 --- hal/audio_extn/utils.c | 6 +++++- hal/audio_hw.c | 26 ++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c index 56b7f463..32cdcc85 100644 --- a/hal/audio_extn/utils.c +++ b/hal/audio_extn/utils.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved. + * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved. * Not a Contribution. * * Copyright (C) 2014 The Android Open Source Project @@ -351,6 +351,7 @@ void audio_extn_utils_update_streams_output_cfg_list(void *platform, root = config_node("", ""); if (root == NULL) { ALOGE("cfg_list, NULL config root"); + free(data); return; } @@ -358,6 +359,9 @@ void audio_extn_utils_update_streams_output_cfg_list(void *platform, load_output(root, platform, streams_output_cfg_list); send_app_type_cfg(platform, mixer, streams_output_cfg_list); + + config_free(root); + free(data); } void audio_extn_utils_dump_streams_output_cfg_list( diff --git a/hal/audio_hw.c b/hal/audio_hw.c index 08df4624..c383aed8 100644 --- a/hal/audio_hw.c +++ b/hal/audio_hw.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. + * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved. * Not a Contribution. * * Copyright (C) 2013 The Android Open Source Project @@ -1986,7 +1986,7 @@ static char* out_get_parameters(const struct audio_stream *stream, const char *k { struct stream_out *out = (struct stream_out *)stream; struct str_parms *query = str_parms_create_str(keys); - char *str; + char *str = (char*) NULL; char value[256]; struct str_parms *reply = str_parms_create(); size_t i, j; @@ -1994,6 +1994,12 @@ static char* out_get_parameters(const struct audio_stream *stream, const char *k bool first = true; if (!query || !reply) { + if (reply) { + str_parms_destroy(reply); + } + if (query) { + str_parms_destroy(query); + } ALOGE("out_get_parameters: failed to allocate mem for query or reply"); return NULL; } @@ -2039,6 +2045,8 @@ static char* out_get_parameters(const struct audio_stream *stream, const char *k strlcat(value, "false", sizeof(value)); } str_parms_add_str(reply, "is_direct_pcm_track", value); + if (str) + free(str); str = str_parms_to_str(reply); } @@ -2061,6 +2069,8 @@ static char* out_get_parameters(const struct audio_stream *stream, const char *k i++; } str_parms_add_str(reply, AUDIO_PARAMETER_STREAM_SUP_FORMATS, value); + if (str) + free(str); str = str_parms_to_str(reply); } str_parms_destroy(query); @@ -2620,6 +2630,12 @@ static char* in_get_parameters(const struct audio_stream *stream, struct str_parms *reply = str_parms_create(); if (!query || !reply) { + if (reply) { + str_parms_destroy(reply); + } + if (query) { + str_parms_destroy(query); + } ALOGE("in_get_parameters: failed to create query or reply"); return NULL; } @@ -3340,6 +3356,12 @@ static char* adev_get_parameters(const struct audio_hw_device *dev, int ret = 0; if (!query || !reply) { + if (reply) { + str_parms_destroy(reply); + } + if (query) { + str_parms_destroy(query); + } ALOGE("adev_get_parameters: failed to create query or reply"); return NULL; } -- cgit v1.2.3