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

[Xen-devel] [PATCH] xen/blkback: prevent leak of mode during multiple backend_changed calls



backend_changed might be called multiple times, which will leak
be->mode. free the previous value before storing the current mode value.

Signed-off-by: Olaf Hering <olaf@xxxxxxxxx>
---

!! Not compile tested !!

 drivers/block/xen-blkback/xenbus.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/block/xen-blkback/xenbus.c 
b/drivers/block/xen-blkback/xenbus.c
index a6585a4..8650b19 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -502,7 +502,7 @@ static void backend_changed(struct xenbus_watch *watch,
                = container_of(watch, struct backend_info, backend_watch);
        struct xenbus_device *dev = be->dev;
        int cdrom = 0;
-       char *device_type;
+       char *mode, *device_type;
 
        DPRINTK("");
 
@@ -528,13 +528,15 @@ static void backend_changed(struct xenbus_watch *watch,
                return;
        }
 
-       be->mode = xenbus_read(XBT_NIL, dev->nodename, "mode", NULL);
-       if (IS_ERR(be->mode)) {
-               err = PTR_ERR(be->mode);
+       mode = xenbus_read(XBT_NIL, dev->nodename, "mode", NULL);
+       kfree(be->mode);
+       if (IS_ERR(mode)) {
+               err = PTR_ERR(mode);
                be->mode = NULL;
                xenbus_dev_fatal(dev, err, "reading mode");
                return;
        }
+       be->mode = mode;
 
        device_type = xenbus_read(XBT_NIL, dev->otherend, "device-type", NULL);
        if (!IS_ERR(device_type)) {
@@ -555,7 +557,7 @@ static void backend_changed(struct xenbus_watch *watch,
                be->minor = minor;
 
                err = xen_vbd_create(be->blkif, handle, major, minor,
-                                (NULL == strchr(be->mode, 'w')), cdrom);
+                                (NULL == strchr(mode, 'w')), cdrom);
                if (err) {
                        be->major = 0;
                        be->minor = 0;
-- 
1.8.0.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.