[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] libvirt-override.c: avoid a leak upon call with invalid argument




>From 49d7a268574772d362dc374b531ff80ec87f5062 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering redhat com>
Date: Tue, 16 Feb 2010 08:07:38 +0100
Subject: [PATCH] libvirt-override.c: avoid a leak upon call with invalid argument

* python/libvirt-override.c (libvirt_virConnectBaselineCPU): Don't leak
the xmlcpus buffer upon encountering a non-string list element.
---
 python/libvirt-override.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index a71766a..2447ad7 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -1,16 +1,16 @@
 /*
  * libvir.c: this modules implements the main part of the glue of the
  *           libvir library and the Python interpreter. It provides the
  *           entry points where an automatically generated stub is
  *           unpractical
  *
- * Copyright (C) 2005, 2007-2009 Red Hat, Inc.
+ * Copyright (C) 2005, 2007-2010 Red Hat, Inc.
  *
  * Daniel Veillard <veillard redhat com>
  */

 #include <config.h>

 /* Horrible kludge to work around even more horrible name-space pollution
    via Python.h.  That file includes /usr/include/python2.5/pyconfig*.h,
    which has over 180 autoconf-style HAVE_* definitions.  Shame on them.  */
@@ -2040,20 +2040,22 @@ libvirt_virConnectBaselineCPU(PyObject *self ATTRIBUTE_UNUSED,
     if (PyList_Check(list)) {
         int i;

         ncpus = PyList_Size(list);
         if ((xmlcpus = malloc(ncpus * sizeof(*xmlcpus))) == NULL)
             return VIR_PY_INT_FAIL;

         for (i = 0; i < ncpus; i++) {
             xmlcpus[i] = PyString_AsString(PyList_GetItem(list, i));
-            if (xmlcpus[i] == NULL)
+            if (xmlcpus[i] == NULL) {
+                free(xmlcpus);
                 return VIR_PY_INT_FAIL;
+            }
         }
     }

     LIBVIRT_BEGIN_ALLOW_THREADS;
     base_cpu = virConnectBaselineCPU(conn, xmlcpus, ncpus, flags);
     LIBVIRT_END_ALLOW_THREADS;

     free(xmlcpus);

--
1.7.0.181.g41533


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]