diff options
author | Smriti Gupta <smritig@codeaurora.org> | 2017-12-06 15:00:40 +0530 |
---|---|---|
committer | Smriti Gupta <smritig@codeaurora.org> | 2017-12-19 10:31:35 +0530 |
commit | ee397206894cfb727b8b2ce021f584f737518d17 (patch) | |
tree | aa8d4bae76eb87bb59a76ff55d5d25844145790b /jni/ConfFileParser.cpp | |
parent | e305fb50f718a898b09a65433400d9069239a70a (diff) | |
download | android_vendor_qcom_opensource_fm-commonsys-ee397206894cfb727b8b2ce021f584f737518d17.tar.gz android_vendor_qcom_opensource_fm-commonsys-ee397206894cfb727b8b2ce021f584f737518d17.tar.bz2 android_vendor_qcom_opensource_fm-commonsys-ee397206894cfb727b8b2ce021f584f737518d17.zip |
iFM: Removing Memory leaks from the HAL Test Code
Test code had some of the allocs not freed up, added code
to free up the leaks.
Change-Id: I20a61e76f006334731378c01800cf6ad14a69e49
CRs-Fixed: 2159776
Diffstat (limited to 'jni/ConfFileParser.cpp')
-rw-r--r-- | jni/ConfFileParser.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/jni/ConfFileParser.cpp b/jni/ConfFileParser.cpp index 1644585..444d3c3 100644 --- a/jni/ConfFileParser.cpp +++ b/jni/ConfFileParser.cpp @@ -790,8 +790,8 @@ static char line_is_key_value_pair ) { const char *equal_start; - char *key; - char *val; + char *key = NULL; + char *val = NULL; unsigned key_len; unsigned val_len; @@ -819,6 +819,10 @@ static char line_is_key_value_pair val = (char *)malloc(sizeof(char) * (val_len + 1)); if(val == NULL) { ALOGE("could not alloc memory for value\n"); + if(key){ + free(key); + key = NULL; + } return FALSE; } memcpy(key, (str - key_len), key_len); @@ -866,20 +870,20 @@ static char add_key_value_pair list = grp->list[key_index]; }else { ALOGE("group list is null\n"); - return FALSE; + goto err; } while((list != NULL) && strcmp(key, list->key)) { list = list->next; } if(list != NULL) { ALOGE("group already contains the key\n"); - return FALSE; + goto err; }else{ list = alloc_key_value_pair(); if(list == NULL) { ALOGE("add key value failed as could not alloc memory for key\ val pair\n"); - return FALSE; + goto err; } key_len = strlen(key); list->key = (char *)malloc(sizeof(char) * @@ -887,7 +891,7 @@ static char add_key_value_pair if(list->key == NULL) { ALOGE("could not alloc memory for key\n"); free(list); - return FALSE; + goto err; } val_len = strlen(val); list->value = (char *)malloc(sizeof(char) * @@ -895,10 +899,12 @@ static char add_key_value_pair if(!list->value) { free(list->key); free(list); - return FALSE; + goto err; } memcpy(list->key, key, key_len); memcpy(list->value, val, val_len); + if (key) free((char*)key); + if (val) free((char*)val); list->key[key_len] = '\0'; list->value[val_len] = '\0'; list->next = grp->list[key_index]; @@ -910,8 +916,10 @@ static char add_key_value_pair grp = grp->grp_next; } ALOGE("group does not exist\n"); - return FALSE; - }else { - return FALSE; + goto err; } +err: + if (key) free((char*)key); + if (val) free((char*)val); + return FALSE; } |