Fix configfile memory leaks

This commit is contained in:
Martin Lund 2022-06-04 20:36:45 +02:00
parent 8a83d2a973
commit 5b7191ed7c

View file

@ -236,18 +236,26 @@ static int resolve_config_file(void)
return 0; return 0;
} }
free(c->path);
asprintf(&c->path, "%s/.config/tio/tiorc", getenv("HOME")); asprintf(&c->path, "%s/.config/tio/tiorc", getenv("HOME"));
if (!access(c->path, F_OK)) if (!access(c->path, F_OK))
{ {
return 0; return 0;
} }
free(c->path);
asprintf(&c->path, "%s/.tiorc", getenv("HOME")); asprintf(&c->path, "%s/.tiorc", getenv("HOME"));
if (!access(c->path, F_OK)) if (!access(c->path, F_OK))
{ {
return 0; return 0;
} }
free(c->path);
c->path = NULL;
return -EINVAL; return -EINVAL;
} }
@ -333,7 +341,7 @@ void config_file_print()
tio_printf(" Path: %s", c->path); tio_printf(" Path: %s", c->path);
if (c->section_name != NULL) if (c->section_name != NULL)
{ {
tio_printf(" Active config section: %s", c->section_name); tio_printf(" Active sub-configuration: %s", c->section_name);
} }
} }
} }