[libvirt] [PATCH 2/3] cpuGetModels: Fix memory leak on error

Jiri Denemark jdenemar at redhat.com
Fri May 13 21:23:29 UTC 2016


Signed-off-by: Jiri Denemark <jdenemar at redhat.com>
---
 src/cpu/cpu_ppc64.c | 4 +++-
 src/cpu/cpu_x86.c   | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c
index 364c8ed..1aed984 100644
--- a/src/cpu/cpu_ppc64.c
+++ b/src/cpu/cpu_ppc64.c
@@ -886,8 +886,10 @@ ppc64DriverGetModels(char ***models)
             if (VIR_STRDUP(name, model->name) < 0)
                 goto error;
 
-            if (VIR_APPEND_ELEMENT(*models, nmodels, name) < 0)
+            if (VIR_APPEND_ELEMENT(*models, nmodels, name) < 0) {
+                VIR_FREE(name);
                 goto error;
+            }
         } else {
             nmodels++;
         }
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index b7f1690..c6aacc1 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -2219,8 +2219,10 @@ x86GetModels(char ***models)
             if (VIR_STRDUP(name, model->name) < 0)
                 goto error;
 
-            if (VIR_APPEND_ELEMENT(*models, nmodels, name) < 0)
+            if (VIR_APPEND_ELEMENT(*models, nmodels, name) < 0) {
+                VIR_FREE(name);
                 goto error;
+            }
         } else {
             nmodels++;
         }
-- 
2.8.2




More information about the libvir-list mailing list