Blame SOURCES/0009-src-syntax.c-interpreter_init-fix-memleak-on-load_mo.patch

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