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-changelog

[Xen-changelog] [xen-unstable] mini-os: Fix memory leaks in blkfront, ne

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] mini-os: Fix memory leaks in blkfront, netfront, pcifront, etc.
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 14 Dec 2009 01:55:11 -0800
Delivery-date: Mon, 14 Dec 2009 01:55:21 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1260784267 0
# Node ID 23bc248302df09154b8808bc09cbf984ba07e6de
# Parent  0cb22e32795c8f9a15cc75f8a7aeba54ca5c1ff0
mini-os: Fix memory leaks in blkfront, netfront, pcifront, etc.

The return value of Xenbus routines xenbus_transaction_start(),
xenbus_printf(), xenbus_transaction_end(), etc.  is a pointer of error
message.  This pointer should be passed to free() to release the
allocated memory when it is no longer needed.

Signed-off-by: Yu Zhiguo <yuzg@xxxxxxxxxxxxxx>
---
 extras/mini-os/blkfront.c             |   17 +++++++++++++----
 extras/mini-os/console/xencons_ring.c |    9 +++++++--
 extras/mini-os/fbfront.c              |   34 ++++++++++++++++++++++++++--------
 extras/mini-os/fs-front.c             |   13 +++++++++----
 extras/mini-os/netfront.c             |   17 +++++++++++++----
 extras/mini-os/pcifront.c             |   14 +++++++++++---
 extras/mini-os/xenbus/xenbus.c        |    3 ++-
 7 files changed, 81 insertions(+), 26 deletions(-)

diff -r 0cb22e32795c -r 23bc248302df extras/mini-os/blkfront.c
--- a/extras/mini-os/blkfront.c Mon Dec 14 09:48:47 2009 +0000
+++ b/extras/mini-os/blkfront.c Mon Dec 14 09:51:07 2009 +0000
@@ -93,7 +93,7 @@ struct blkfront_dev *init_blkfront(char 
     char* message=NULL;
     struct blkif_sring *s;
     int retry=0;
-    char* msg;
+    char* msg = NULL;
     char* c;
     char* nodename = _nodename ? _nodename : "device/vbd/768";
 
@@ -129,6 +129,7 @@ again:
     err = xenbus_transaction_start(&xbt);
     if (err) {
         printk("starting transaction\n");
+        free(err);
     }
 
     err = xenbus_printf(xbt, nodename, "ring-ref","%u",
@@ -159,6 +160,7 @@ again:
 
 
     err = xenbus_transaction_end(xbt, 0, &retry);
+    if (err) free(err);
     if (retry) {
             goto again;
         printk("completing transaction\n");
@@ -167,7 +169,8 @@ again:
     goto done;
 
 abort_transaction:
-    xenbus_transaction_end(xbt, 1, &retry);
+    free(err);
+    err = xenbus_transaction_end(xbt, 1, &retry);
     goto error;
 
 done:
@@ -238,6 +241,8 @@ done:
     return dev;
 
 error:
+    free(msg);
+    free(err);
     free_blkfront(dev);
     return NULL;
 }
@@ -265,6 +270,7 @@ void shutdown_blkfront(struct blkfront_d
     state = xenbus_read_integer(path);
     while (err == NULL && state < XenbusStateClosing)
         err = xenbus_wait_for_state_change(path, &state, &dev->events);
+    if (err) free(err);
 
     if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosed)) != 
NULL) {
         printk("shutdown_blkfront: error changing state to %d: %s\n",
@@ -272,8 +278,10 @@ void shutdown_blkfront(struct blkfront_d
         goto close;
     }
     state = xenbus_read_integer(path);
-    if (state < XenbusStateClosed)
-        xenbus_wait_for_state_change(path, &state, &dev->events);
+    if (state < XenbusStateClosed) {
+        err = xenbus_wait_for_state_change(path, &state, &dev->events);
+        if (err) free(err);
+    }
 
     if ((err = xenbus_switch_state(XBT_NIL, nodename, 
XenbusStateInitialising)) != NULL) {
         printk("shutdown_blkfront: error changing state to %d: %s\n",
@@ -286,6 +294,7 @@ void shutdown_blkfront(struct blkfront_d
         err = xenbus_wait_for_state_change(path, &state, &dev->events);
 
 close:
+    if (err) free(err);
     xenbus_unwatch_path_token(XBT_NIL, path, path);
 
     snprintf(path, sizeof(path), "%s/ring-ref", nodename);
diff -r 0cb22e32795c -r 23bc248302df extras/mini-os/console/xencons_ring.c
--- a/extras/mini-os/console/xencons_ring.c     Mon Dec 14 09:48:47 2009 +0000
+++ b/extras/mini-os/console/xencons_ring.c     Mon Dec 14 09:51:07 2009 +0000
@@ -203,7 +203,7 @@ struct consfront_dev *init_consfront(cha
     char* err;
     char* message=NULL;
     int retry=0;
-    char* msg;
+    char* msg = NULL;
     char nodename[256];
     char path[256];
     static int consfrontends = 1;
@@ -242,6 +242,7 @@ again:
     err = xenbus_transaction_start(&xbt);
     if (err) {
         printk("starting transaction\n");
+        free(err);
     }
 
     err = xenbus_printf(xbt, nodename, "ring-ref","%u",
@@ -278,6 +279,7 @@ again:
 
 
     err = xenbus_transaction_end(xbt, 0, &retry);
+    if (err) free(err);
     if (retry) {
             goto again;
         printk("completing transaction\n");
@@ -286,7 +288,8 @@ again:
     goto done;
 
 abort_transaction:
-    xenbus_transaction_end(xbt, 1, &retry);
+    free(err);
+    err = xenbus_transaction_end(xbt, 1, &retry);
     goto error;
 
 done:
@@ -323,6 +326,8 @@ done:
     return dev;
 
 error:
+    free(msg);
+    free(err);
     free_consfront(dev);
     return NULL;
 }
diff -r 0cb22e32795c -r 23bc248302df extras/mini-os/fbfront.c
--- a/extras/mini-os/fbfront.c  Mon Dec 14 09:48:47 2009 +0000
+++ b/extras/mini-os/fbfront.c  Mon Dec 14 09:51:07 2009 +0000
@@ -71,7 +71,7 @@ struct kbdfront_dev *init_kbdfront(char 
     char* message=NULL;
     struct xenkbd_page *s;
     int retry=0;
-    char* msg;
+    char* msg = NULL;
     char* nodename = _nodename ? _nodename : "device/vkbd/0";
     struct kbdfront_dev *dev;
 
@@ -102,6 +102,7 @@ again:
     err = xenbus_transaction_start(&xbt);
     if (err) {
         printk("starting transaction\n");
+        free(err);
     }
 
     err = xenbus_printf(xbt, nodename, "page-ref","%u", virt_to_mfn(s));
@@ -124,11 +125,13 @@ again:
 
     snprintf(path, sizeof(path), "%s/state", nodename);
     err = xenbus_switch_state(xbt, path, XenbusStateInitialised);
-    if (err)
+    if (err) {
         printk("error writing initialized: %s\n", err);
-
+        free(err);
+    }
 
     err = xenbus_transaction_end(xbt, 0, &retry);
+    if (err) free(err);
     if (retry) {
             goto again;
         printk("completing transaction\n");
@@ -137,7 +140,8 @@ again:
     goto done;
 
 abort_transaction:
-    xenbus_transaction_end(xbt, 1, &retry);
+    free(err);
+    err = xenbus_transaction_end(xbt, 1, &retry);
     goto error;
 
 done:
@@ -186,6 +190,8 @@ done:
 
     return dev;
 error:
+    free(msg);
+    free(err);
     free_kbdfront(dev);
     return NULL;
 }
@@ -247,6 +253,7 @@ void shutdown_kbdfront(struct kbdfront_d
     state = xenbus_read_integer(path);
     while (err == NULL && state < XenbusStateClosing)
         err = xenbus_wait_for_state_change(path, &state, &dev->events);
+    if (err) free(err);
 
     if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosed)) != 
NULL) {
         printk("shutdown_kbdfront: error changing state to %d: %s\n",
@@ -254,8 +261,10 @@ void shutdown_kbdfront(struct kbdfront_d
         goto close_kbdfront;
     }
     state = xenbus_read_integer(path);
-    if (state < XenbusStateClosed)
-        xenbus_wait_for_state_change(path, &state, &dev->events);
+    if (state < XenbusStateClosed) {
+        err = xenbus_wait_for_state_change(path, &state, &dev->events);
+        if (err) free(err);
+    }
 
     if ((err = xenbus_switch_state(XBT_NIL, nodename, 
XenbusStateInitialising)) != NULL) {
         printk("shutdown_kbdfront: error changing state to %d: %s\n",
@@ -266,6 +275,7 @@ void shutdown_kbdfront(struct kbdfront_d
     //xenbus_wait_for_value(path, "2", &dev->events);
 
 close_kbdfront:
+    if (err) free(err);
     xenbus_unwatch_path_token(XBT_NIL, path, path);
 
     snprintf(path, sizeof(path), "%s/page-ref", nodename);
@@ -446,6 +456,7 @@ again:
     err = xenbus_transaction_start(&xbt);
     if (err) {
         printk("starting transaction\n");
+        free(err);
     }
 
     err = xenbus_printf(xbt, nodename, "page-ref","%u", virt_to_mfn(s));
@@ -478,6 +489,7 @@ again:
     }
 
     err = xenbus_transaction_end(xbt, 0, &retry);
+    if (err) free(err);
     if (retry) {
             goto again;
         printk("completing transaction\n");
@@ -486,7 +498,8 @@ again:
     goto done;
 
 abort_transaction:
-    xenbus_transaction_end(xbt, 1, &retry);
+    free(err);
+    err = xenbus_transaction_end(xbt, 1, &retry);
     goto error;
 
 done:
@@ -539,6 +552,7 @@ done:
     return dev;
 
 error:
+    free(err);
     free_fbfront(dev);
     return NULL;
 }
@@ -627,6 +641,7 @@ void shutdown_fbfront(struct fbfront_dev
     state = xenbus_read_integer(path);
     while (err == NULL && state < XenbusStateClosing)
         err = xenbus_wait_for_state_change(path, &state, &dev->events);
+    if (err) free(err);
 
     if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosed)) != 
NULL) {
         printk("shutdown_fbfront: error changing state to %d: %s\n",
@@ -634,8 +649,10 @@ void shutdown_fbfront(struct fbfront_dev
         goto close_fbfront;
     }
     state = xenbus_read_integer(path);
-    if (state < XenbusStateClosed)
+    if (state < XenbusStateClosed) {
         xenbus_wait_for_state_change(path, &state, &dev->events);
+        if (err) free(err);
+    }
 
     if ((err = xenbus_switch_state(XBT_NIL, nodename, 
XenbusStateInitialising)) != NULL) {
         printk("shutdown_fbfront: error changing state to %d: %s\n",
@@ -646,6 +663,7 @@ void shutdown_fbfront(struct fbfront_dev
     //xenbus_wait_for_value(path, "2", &dev->events);
 
 close_fbfront:
+    if (err) free(err);
     xenbus_unwatch_path_token(XBT_NIL, path, path);
 
     snprintf(path, sizeof(path), "%s/page-ref", nodename);
diff -r 0cb22e32795c -r 23bc248302df extras/mini-os/fs-front.c
--- a/extras/mini-os/fs-front.c Mon Dec 14 09:48:47 2009 +0000
+++ b/extras/mini-os/fs-front.c Mon Dec 14 09:51:07 2009 +0000
@@ -1103,6 +1103,7 @@ again:
     err = xenbus_transaction_start(&xbt);
     if (err) {
         printk("starting transaction\n");
+        free(err);
     }
     
     err = xenbus_printf(xbt, 
@@ -1140,9 +1141,10 @@ again:
     }
 
     err = xenbus_printf(xbt, nodename, "state", STATE_READY, 0xdeadbeef);
-
-    
+    if (err) free(err);
+
     err = xenbus_transaction_end(xbt, 0, &retry);
+    if (err) free(err);
     if (retry) {
             goto again;
         printk("completing transaction\n");
@@ -1159,7 +1161,9 @@ again:
     goto done;
 
 abort_transaction:
-    xenbus_transaction_end(xbt, 1, &retry);
+    free(err);
+    err = xenbus_transaction_end(xbt, 1, &retry);
+    if (err) free(err);
 
 done:
 
@@ -1189,7 +1193,8 @@ done:
     sprintf(token, "fs-front-%d", import->import_id);
     /* The token will not be unique if multiple imports are inited */
     xenbus_watch_path_token(XBT_NIL, r_nodename, r_nodename, &events);
-    xenbus_wait_for_value(r_nodename, STATE_READY, &events);
+    err = xenbus_wait_for_value(r_nodename, STATE_READY, &events);
+    if (err) free(err);
     xenbus_unwatch_path_token(XBT_NIL, r_nodename, r_nodename);
     printk("Backend ready.\n");
    
diff -r 0cb22e32795c -r 23bc248302df extras/mini-os/netfront.c
--- a/extras/mini-os/netfront.c Mon Dec 14 09:48:47 2009 +0000
+++ b/extras/mini-os/netfront.c Mon Dec 14 09:51:07 2009 +0000
@@ -305,7 +305,7 @@ struct netfront_dev *init_netfront(char 
     struct netif_rx_sring *rxs;
     int retry=0;
     int i;
-    char* msg;
+    char* msg = NULL;
     char nodename[256];
     char path[256];
     struct netfront_dev *dev;
@@ -377,6 +377,7 @@ again:
     err = xenbus_transaction_start(&xbt);
     if (err) {
         printk("starting transaction\n");
+        free(err);
     }
 
     err = xenbus_printf(xbt, nodename, "tx-ring-ref","%u",
@@ -413,6 +414,7 @@ again:
     }
 
     err = xenbus_transaction_end(xbt, 0, &retry);
+    if (err) free(err);
     if (retry) {
             goto again;
         printk("completing transaction\n");
@@ -421,7 +423,8 @@ again:
     goto done;
 
 abort_transaction:
-    xenbus_transaction_end(xbt, 1, &retry);
+    free(err);
+    err = xenbus_transaction_end(xbt, 1, &retry);
     goto error;
 
 done:
@@ -479,6 +482,8 @@ done:
 
     return dev;
 error:
+    free(msg);
+    free(err);
     free_netfront(dev);
     return NULL;
 }
@@ -521,6 +526,7 @@ void shutdown_netfront(struct netfront_d
     state = xenbus_read_integer(path);
     while (err == NULL && state < XenbusStateClosing)
         err = xenbus_wait_for_state_change(path, &state, &dev->events);
+    if (err) free(err);
 
     if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosed)) != 
NULL) {
         printk("shutdown_netfront: error changing state to %d: %s\n",
@@ -528,8 +534,10 @@ void shutdown_netfront(struct netfront_d
         goto close;
     }
     state = xenbus_read_integer(path);
-    if (state < XenbusStateClosed)
-        xenbus_wait_for_state_change(path, &state, &dev->events);
+    if (state < XenbusStateClosed) {
+        err = xenbus_wait_for_state_change(path, &state, &dev->events);
+        if (err) free(err);
+    }
 
     if ((err = xenbus_switch_state(XBT_NIL, nodename, 
XenbusStateInitialising)) != NULL) {
         printk("shutdown_netfront: error changing state to %d: %s\n",
@@ -542,6 +550,7 @@ void shutdown_netfront(struct netfront_d
         err = xenbus_wait_for_state_change(path, &state, &dev->events);
 
 close:
+    if (err) free(err);
     xenbus_unwatch_path_token(XBT_NIL, path, path);
 
     snprintf(path, sizeof(path), "%s/tx-ring-ref", nodename);
diff -r 0cb22e32795c -r 23bc248302df extras/mini-os/pcifront.c
--- a/extras/mini-os/pcifront.c Mon Dec 14 09:48:47 2009 +0000
+++ b/extras/mini-os/pcifront.c Mon Dec 14 09:51:07 2009 +0000
@@ -181,6 +181,7 @@ again:
     err = xenbus_transaction_start(&xbt);
     if (err) {
         printk("starting transaction\n");
+        free(err);
     }
 
     err = xenbus_printf(xbt, nodename, "pci-op-ref","%u",
@@ -210,6 +211,7 @@ again:
     }
 
     err = xenbus_transaction_end(xbt, 0, &retry);
+    if (err) free(err);
     if (retry) {
             goto again;
         printk("completing transaction\n");
@@ -218,7 +220,8 @@ again:
     goto done;
 
 abort_transaction:
-    xenbus_transaction_end(xbt, 1, &retry);
+    free(err);
+    err = xenbus_transaction_end(xbt, 1, &retry);
     goto error;
 
 done:
@@ -268,6 +271,7 @@ done:
     return dev;
 
 error:
+    free(err);
     free_pcifront(dev);
     return NULL;
 }
@@ -341,6 +345,7 @@ void shutdown_pcifront(struct pcifront_d
     state = xenbus_read_integer(path);
     while (err == NULL && state < XenbusStateClosing)
         err = xenbus_wait_for_state_change(path, &state, &dev->events);
+    if (err) free(err);
 
     if ((err = xenbus_switch_state(XBT_NIL, nodename, XenbusStateClosed)) != 
NULL) {
         printk("shutdown_pcifront: error changing state to %d: %s\n",
@@ -348,8 +353,10 @@ void shutdown_pcifront(struct pcifront_d
         goto close_pcifront;
     }
     state = xenbus_read_integer(path);
-    if (state < XenbusStateClosed)
-        xenbus_wait_for_state_change(path, &state, &dev->events);
+    if (state < XenbusStateClosed) {
+        err = xenbus_wait_for_state_change(path, &state, &dev->events);
+        free(err);
+    }
 
     if ((err = xenbus_switch_state(XBT_NIL, nodename, 
XenbusStateInitialising)) != NULL) {
         printk("shutdown_pcifront: error changing state to %d: %s\n",
@@ -362,6 +369,7 @@ void shutdown_pcifront(struct pcifront_d
         err = xenbus_wait_for_state_change(path, &state, &dev->events);
 
 close_pcifront:
+    if (err) free(err);
     xenbus_unwatch_path_token(XBT_NIL, path, path);
 
     snprintf(path, sizeof(path), "%s/info-ref", nodename);
diff -r 0cb22e32795c -r 23bc248302df extras/mini-os/xenbus/xenbus.c
--- a/extras/mini-os/xenbus/xenbus.c    Mon Dec 14 09:48:47 2009 +0000
+++ b/extras/mini-os/xenbus/xenbus.c    Mon Dec 14 09:51:07 2009 +0000
@@ -135,7 +135,8 @@ char *xenbus_switch_state(xenbus_transac
 
     do {
         if (xbt == XBT_NIL) {
-            xenbus_transaction_start(&xbt);
+            msg = xenbus_transaction_start(&xbt);
+            if (msg) goto exit;
             xbt_flag = 1;
         }
 

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] mini-os: Fix memory leaks in blkfront, netfront, pcifront, etc., Xen patchbot-unstable <=