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

Jim Meyering jim at meyering.net
Tue Feb 16 07:10:52 UTC 2010



>From 49d7a268574772d362dc374b531ff80ec87f5062 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at 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 at 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




More information about the libvir-list mailing list