hal: Fix potential memory leaks in HAL
Fix potential memory leaks in HAL
Change-Id: Ifd491cc185a7d1afa647f03639e57d1685d18803
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index ae7853e..f8b9652 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2148,7 +2148,7 @@
{
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;
@@ -2156,6 +2156,12 @@
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;
}
@@ -2201,6 +2207,8 @@
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);
}
@@ -2223,6 +2231,8 @@
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);
@@ -2808,6 +2818,12 @@
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;
}
@@ -3528,6 +3544,12 @@
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;
}