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

[libvirt] [PATCH] domain_event.c: don't deref NULL on an OOM error path



This fixes a pair of potential segfault-inducing bugs:

>From 7ca7e9cd366b17e41da9207b68de7e9166a88da2 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering redhat com>
Date: Mon, 29 Mar 2010 17:43:01 +0200
Subject: [PATCH] domain_event.c: don't deref NULL on an OOM error path

* src/conf/domain_event.c (virDomainEventGraphicsNewFromDom):
Return NULL when handling out-of-memory error, rather than
falling through with ev=NULL and then assigning to ev->member.
(virDomainEventGraphicsNewFromObj): Likewise.
---
 src/conf/domain_event.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 41c70fc..1cf03e3 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -681,19 +681,19 @@ virDomainEventPtr virDomainEventGraphicsNewFromDom(virDomainPtr dom,
 {
     virDomainEventPtr ev =
         virDomainEventNewInternal(VIR_DOMAIN_EVENT_ID_GRAPHICS,
                                   dom->id, dom->name, dom->uuid);

     if (ev) {
         ev->data.graphics.phase = phase;
         if (!(ev->data.graphics.authScheme = strdup(authScheme))) {
             virDomainEventFree(ev);
-            ev = NULL;
+            return NULL;
         }
         ev->data.graphics.local = local;
         ev->data.graphics.remote = remote;
         ev->data.graphics.subject = subject;
     }

     return ev;
 }

@@ -706,19 +706,19 @@ virDomainEventPtr virDomainEventGraphicsNewFromObj(virDomainObjPtr obj,
 {
     virDomainEventPtr ev =
         virDomainEventNewInternal(VIR_DOMAIN_EVENT_ID_GRAPHICS,
                                   obj->def->id, obj->def->name, obj->def->uuid);

     if (ev) {
         ev->data.graphics.phase = phase;
         if (!(ev->data.graphics.authScheme = strdup(authScheme))) {
             virDomainEventFree(ev);
-            ev = NULL;
+            return NULL;
         }
         ev->data.graphics.local = local;
         ev->data.graphics.remote = remote;
         ev->data.graphics.subject = subject;
     }

     return ev;
 }

--
1.7.0.3.448.g82eeb


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