Clean up memory management when loading IMC/IMVs from files

This commit is contained in:
Martin Willi
2012-11-30 15:47:34 +01:00
parent db9c8b6fba
commit cd74959465
5 changed files with 38 additions and 58 deletions
+4 -6
View File
@@ -163,9 +163,7 @@ static bool load_imcvs_from_config(char *filename, bool is_imc)
}
/* copy the IMC/IMV name */
name = malloc(token.len + 1);
memcpy(name, token.ptr, token.len);
name[token.len] = '\0';
name = strndup(token.ptr, token.len);
/* advance to the IMC/IMV path and extract it */
if (!eat_whitespace(&line))
@@ -180,9 +178,7 @@ static bool load_imcvs_from_config(char *filename, bool is_imc)
}
/* copy the IMC/IMV path */
path = malloc(token.len + 1);
memcpy(path, token.ptr, token.len);
path[token.len] = '\0';
path = strndup(token.ptr, token.len);
/* load and register an IMC/IMV instance */
if (is_imc)
@@ -193,6 +189,8 @@ static bool load_imcvs_from_config(char *filename, bool is_imc)
{
success = tnc->imvs->load(tnc->imvs, name, path);
}
free(name);
free(path);
if (!success)
{
break;