From 7d296f655e21e0e6866e783c534fee4629bc7a38 Mon Sep 17 00:00:00 2001
From: Pino Toscano <ptoscano@redhat.com>
Date: Fri, 20 Jul 2018 16:30:26 +0200
Subject: [PATCH] * src/syntax.c (interpreter_init): fix memleak on load_module
fail
If load_module fails, then name is not freed. Instead, store the
return value of load_module separately, cleanup name, and then check
that value.
(cherry picked from commit d5a6da8a8e302b8bf1fe35ae0bdd0433e522ddf2)
---
src/syntax.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/syntax.c b/src/syntax.c
index d26babcc..f9f2849e 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -2060,6 +2060,7 @@ int interpreter_init(struct augeas *aug) {
for (int i=0; i < globbuf.gl_pathc; i++) {
char *name, *p, *q;
+ int res;
p = strrchr(globbuf.gl_pathv[i], SEP);
if (p == NULL)
p = globbuf.gl_pathv[i];
@@ -2068,9 +2069,10 @@ int interpreter_init(struct augeas *aug) {
q = strchr(p, '.');
name = strndup(p, q - p);
name[0] = toupper(name[0]);
- if (load_module(aug, name) == -1)
- goto error;
+ res = load_module(aug, name);
free(name);
+ if (res == -1)
+ goto error;
}
globfree(&globbuf);
return 0;
--
2.17.2