[Xen-devel] [PATCH] linux-2.6.18/fb: fix potential memory leak

Jan Beulich
Tue, 08 Feb 2011 17:15:51 -0000

From: Joe Jin <joe.jin@oracle.com>

This patch fixes a potential memory leak when xenfb connect to
the backend fails.

Thanks for Ian''s review and comments.

[v2: reworded the commit message a bit]

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Joe Jin <joe.jin@oracle.com>
Tested-by: Gurudas Pai <gurudas.pai@oracle.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>

Made apply to linux-2.6.18-xen.hg.

Signed-off-by: Jan Beulich <jbeulich@novell.com>

--- a/drivers/xen/fbfront/xenfb.c
+++ b/drivers/xen/fbfront/xenfb.c
@@ -735,23 +735,22 @@ static void xenfb_init_shared_page(struc
 static int xenfb_connect_backend(struct xenbus_device *dev,
 				 struct xenfb_info *info)
 {
-	int ret;
+	int ret, irq;
 	struct xenbus_transaction xbt;

-	ret = bind_listening_port_to_irqhandler(
+	irq = bind_listening_port_to_irqhandler(
 		dev->otherend_id, xenfb_event_handler, 0, "xenfb", info);
-	if (ret < 0) {
-		xenbus_dev_fatal(dev, ret,
+	if (irq < 0) {
+		xenbus_dev_fatal(dev, irq,
 				 "bind_listening_port_to_irqhandler");
-		return ret;
+		return irq;
 	}
-	info->irq = ret;

  again:
 	ret = xenbus_transaction_start(&xbt);
 	if (ret) {
 		xenbus_dev_fatal(dev, ret, "starting transaction");
-		return ret;
+		goto unbind_irq;
 	}
 	ret = xenbus_printf(xbt, dev->nodename, "page-ref",
"%lu",
 			    virt_to_mfn(info->page));
@@ -773,15 +772,18 @@ static int xenfb_connect_backend(struct
 		if (ret == -EAGAIN)
 			goto again;
 		xenbus_dev_fatal(dev, ret, "completing transaction");
-		return ret;
+		goto unbind_irq;
 	}

+	info->irq = irq;
 	xenbus_switch_state(dev, XenbusStateInitialised);
 	return 0;

  error_xenbus:
 	xenbus_transaction_end(xbt, 1);
 	xenbus_dev_fatal(dev, ret, "writing xenstore");
+ unbind_irq:
+	unbind_from_irqhandler(irq, info);
 	return ret;
 }






_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com