[libvirt] [PATCH] sexpr_string: avoid leak on OOM error path

Jim Meyering jim at meyering.net
Thu Feb 4 16:55:58 UTC 2010



>From cc06142a81dc1891dc75306b986ea331f5fd5368 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Thu, 4 Feb 2010 17:55:15 +0100
Subject: [PATCH] sexpr_string: avoid leak on OOM error path

* src/xen/sexpr.c (sexpr_string): Free sexpr buffer upon allocation
failure.
---
 src/xen/sexpr.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/src/xen/sexpr.c b/src/xen/sexpr.c
index 085500d..669f8a2 100644
--- a/src/xen/sexpr.c
+++ b/src/xen/sexpr.c
@@ -107,30 +107,31 @@ sexpr_nil(void)
 struct sexpr *
 sexpr_string(const char *str, ssize_t len)
 {
     struct sexpr *ret = sexpr_new();

     if (ret == NULL)
         return ret;
     ret->kind = SEXPR_VALUE;
     if (len > 0) {
         ret->u.value = strndup(str, len);
     } else {
         ret->u.value = strdup(str);
     }

     if (ret->u.value == NULL) {
+        VIR_FREE(ret);
         return NULL;
     }

     return ret;
 }

 /**
  * sexpr_cons:
  * @car: the left operand
  * @cdr: the right operand
  *
  * Implement the CONS operation assembling 2 existing S-Expressions.
  * Note that in case of error the input data are not freed.
  *
  * Returns the resulting S-Expression pointer or NULL in case of error.
--
1.7.0.rc1.199.g9253a




More information about the libvir-list mailing list