From 453414b284599a93944cc893b11f85028c1d7f76 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Mon, 14 Dec 2009 09:51:07 +0000 Subject: 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 --- extras/mini-os/pcifront.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'extras/mini-os/pcifront.c') diff --git a/extras/mini-os/pcifront.c b/extras/mini-os/pcifront.c index b9be949363..641eca4e9f 100644 --- a/extras/mini-os/pcifront.c +++ b/extras/mini-os/pcifront.c @@ -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_dev *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_pcifront: error changing state to %d: %s\n", @@ -348,8 +353,10 @@ void shutdown_pcifront(struct pcifront_dev *dev) 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_dev *dev) 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); -- cgit v1.2.3