Merge "Fix Memory leak in util/loc_cfg.cpp"

This commit is contained in:
Linux Build Service Account 2015-06-13 12:00:47 -07:00 committed by Gerrit - the friendly Code Review server
commit 060ec8f697

View file

@ -330,24 +330,25 @@ int loc_update_conf(const char* conf_data, int32_t length,
// make a copy, so we do not tokenize the original data
char* conf_copy = (char*)malloc(length+1);
if(conf_copy !=NULL)
if (conf_copy != NULL)
{
memcpy(conf_copy, conf_data, length);
// we hard NULL the end of string to be safe
conf_copy[length] = 0;
}
memcpy(conf_copy, conf_data, length);
// we hard NULL the end of string to be safe
conf_copy[length] = 0;
// start with one record off
uint32_t num_params = table_length - 1;
char* saveptr = NULL;
char* input_buf = strtok_r(conf_copy, "\n", &saveptr);
ret = 0;
// start with one record off
uint32_t num_params = table_length - 1;
char* saveptr = NULL;
char* input_buf = strtok_r(conf_copy, "\n", &saveptr);
ret = 0;
LOC_LOGD("%s:%d]: num_params: %d\n", __func__, __LINE__, num_params);
while(num_params && input_buf) {
ret++;
num_params -= loc_fill_conf_item(input_buf, config_table, table_length);
input_buf = strtok_r(NULL, "\n", &saveptr);
LOC_LOGD("%s:%d]: num_params: %d\n", __func__, __LINE__, num_params);
while(num_params && input_buf) {
ret++;
num_params -= loc_fill_conf_item(input_buf, config_table, table_length);
input_buf = strtok_r(NULL, "\n", &saveptr);
}
free(conf_copy);
}
}