WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 4/7] merge review: no malloc failure checks.

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 4/7] merge review: no malloc failure checks.
From: Gerd Hoffmann <kraxel@xxxxxxxxxx>
Date: Tue, 21 Apr 2009 18:38:54 +0200
Cc: Gerd Hoffmann <kraxel@xxxxxxxxxx>
Delivery-date: Tue, 21 Apr 2009 09:39:27 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1240331937-20057-1-git-send-email-kraxel@xxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <1240331937-20057-1-git-send-email-kraxel@xxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
qemu_malloc() will never return errors.  It will abort instead.
Thus no checks for failure are needed.

Signed-off-by: Gerd Hoffmann <kraxel@xxxxxxxxxx>
---
 hw/xen_backend.c |   14 ++++++++++----
 hw/xenfb.c       |    2 --
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/hw/xen_backend.c b/hw/xen_backend.c
index 56b001f..bb02634 100644
--- a/hw/xen_backend.c
+++ b/hw/xen_backend.c
@@ -67,9 +67,17 @@ char *xenstore_read_str(const char *base, const char *node)
 {
     char abspath[XEN_BUFSIZE];
     unsigned int len;
+    char *str, *ret = NULL;
 
     snprintf(abspath, sizeof(abspath), "%s/%s", base, node);
-    return xs_read(xenstore, 0, abspath, &len);
+    str = xs_read(xenstore, 0, abspath, &len);
+    if (str != NULL) {
+        /* move to qemu-allocated memory to make sure
+         * callers can savely qemu_free() stuff. */
+        ret = qemu_strdup(str);
+        free(str);
+    }
+    return ret;
 }
 
 int xenstore_write_int(const char *base, const char *node, int ival)
@@ -184,8 +192,6 @@ static struct XenDevice *xen_be_get_xendev(const char 
*type, int dom, int dev,
 
     /* init new xendev */
     xendev = qemu_mallocz(ops->size);
-    if (!xendev)
-        return NULL;
     xendev->type  = type;
     xendev->dom   = dom;
     xendev->dev   = dev;
@@ -519,7 +525,7 @@ static int xenstore_scan(const char *type, int dom, struct 
XenDevOps *ops)
            continue;
        xen_be_check_state(xendev);
     }
-    qemu_free(dev);
+    free(dev);
     return 0;
 }
 
diff --git a/hw/xenfb.c b/hw/xenfb.c
index 8336c82..1764ac2 100644
--- a/hw/xenfb.c
+++ b/hw/xenfb.c
@@ -483,8 +483,6 @@ static int xenfb_map_fb(struct XenFB *xenfb)
 
     pgmfns = qemu_mallocz(sizeof(unsigned long) * n_fbdirs);
     fbmfns = qemu_mallocz(sizeof(unsigned long) * xenfb->fbpages);
-    if (!pgmfns || !fbmfns)
-       goto out;
 
     xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd);
     map = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,
-- 
1.6.2.2


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel