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
This commit is contained in:
committed by
Michael Bestas
parent
4ba1b7d6ec
commit
735e13a1c1
@@ -791,8 +791,8 @@ static char line_is_key_value_pair
|
||||
)
|
||||
{
|
||||
char *equal_start;
|
||||
char *key;
|
||||
char *val;
|
||||
char *key = NULL;
|
||||
char *val = NULL;
|
||||
unsigned key_len;
|
||||
unsigned val_len;
|
||||
|
||||
@@ -820,6 +820,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);
|
||||
@@ -867,20 +871,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) *
|
||||
@@ -888,7 +892,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) *
|
||||
@@ -896,10 +900,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];
|
||||
@@ -911,8 +917,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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user