Parser: free keywords list and free files
This commit is contained in:
@@ -74,6 +74,7 @@ struct state {
|
|||||||
|
|
||||||
/* TO REMOVE (use a identifier for config and fallback XDG in api functions) */
|
/* TO REMOVE (use a identifier for config and fallback XDG in api functions) */
|
||||||
TAILQ_HEAD(, conf_sec) config;
|
TAILQ_HEAD(, conf_sec) config;
|
||||||
|
static struct keyword *keywords = NULL;
|
||||||
|
|
||||||
static struct keyword *
|
static struct keyword *
|
||||||
push_keyword(struct keyword *tail, enum keyword_t type, char *buf, size_t *offset, struct files *file, int line)
|
push_keyword(struct keyword *tail, enum keyword_t type, char *buf, size_t *offset, struct files *file, int line)
|
||||||
@@ -372,14 +373,8 @@ include(struct keyword *head)
|
|||||||
static void *
|
static void *
|
||||||
free_opt(struct conf_opt *o)
|
free_opt(struct conf_opt *o)
|
||||||
{
|
{
|
||||||
int i;
|
if (o)
|
||||||
if (o) {
|
|
||||||
if (o->name)
|
|
||||||
free(o->name);
|
|
||||||
for (i = 0; o->val[i]; i++)
|
|
||||||
free(o->val[i]);
|
|
||||||
free(o);
|
free(o);
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,7 +473,6 @@ free_sec(struct conf_sec *sec)
|
|||||||
TAILQ_REMOVE(&sec->sub, s, entry);
|
TAILQ_REMOVE(&sec->sub, s, entry);
|
||||||
free_sec(s);
|
free_sec(s);
|
||||||
}
|
}
|
||||||
free(sec->name);
|
|
||||||
free(sec);
|
free(sec);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -539,13 +533,42 @@ int
|
|||||||
free_conf(void)
|
free_conf(void)
|
||||||
{
|
{
|
||||||
struct conf_sec *s;
|
struct conf_sec *s;
|
||||||
struct keyword *kw = NULL;
|
struct keyword *kw, *nkw;
|
||||||
|
struct files **f = NULL;
|
||||||
|
int i, nf = 0;
|
||||||
|
|
||||||
while (!TAILQ_EMPTY(&config)) {
|
while (!TAILQ_EMPTY(&config)) {
|
||||||
s = TAILQ_FIRST(&config);
|
s = TAILQ_FIRST(&config);
|
||||||
TAILQ_REMOVE(&config, s, entry);
|
TAILQ_REMOVE(&config, s, entry);
|
||||||
free_sec(s);
|
free_sec(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kw = keywords;
|
||||||
|
|
||||||
|
while (kw) {
|
||||||
|
nkw = kw->next;
|
||||||
|
|
||||||
|
if (kw->name)
|
||||||
|
free(kw->name);
|
||||||
|
|
||||||
|
for (i = 0; i < nf; i++) {
|
||||||
|
if (f[i] == kw->file) {
|
||||||
|
if (!(f = realloc(f, sizeof(*f) * (++i))))
|
||||||
|
err(EXIT_FAILURE, "realloc");
|
||||||
|
f[i-1] = kw->file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kw = nkw;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nf > 0) {
|
||||||
|
for (i = 0; i < nf; i++) {
|
||||||
|
free(f[i]->name);
|
||||||
|
free(f[i]);
|
||||||
|
}
|
||||||
|
free(f);
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -560,6 +583,8 @@ get_conf(const char *filename)
|
|||||||
if (!head)
|
if (!head)
|
||||||
return -1; /* TODO ERREUR */
|
return -1; /* TODO ERREUR */
|
||||||
|
|
||||||
|
keywords = head;
|
||||||
|
|
||||||
TAILQ_INIT(&config);
|
TAILQ_INIT(&config);
|
||||||
|
|
||||||
while (kw) {
|
while (kw) {
|
||||||
|
|||||||
Reference in New Issue
Block a user