config include: fix leak on relative include path

Found through static analysis
This commit is contained in:
Dominique Martinet 2018-07-01 23:34:07 +09:00
parent 248ea93c1a
commit 8c526bbb03

View file

@ -425,7 +425,7 @@ static bool load_include_config(const char *path, const char *parent_dir,
// save parent config // save parent config
const char *parent_config = config->current_config; const char *parent_config = config->current_config;
char *full_path = strdup(path); char *full_path;
int len = strlen(path); int len = strlen(path);
if (len >= 1 && path[0] != '/') { if (len >= 1 && path[0] != '/') {
len = len + strlen(parent_dir) + 2; len = len + strlen(parent_dir) + 2;
@ -436,6 +436,8 @@ static bool load_include_config(const char *path, const char *parent_dir,
return false; return false;
} }
snprintf(full_path, len, "%s/%s", parent_dir, path); snprintf(full_path, len, "%s/%s", parent_dir, path);
} else {
full_path = strdup(path);
} }
char *real_path = realpath(full_path, NULL); char *real_path = realpath(full_path, NULL);