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] xen-gntdev: Fix memory leak when mmap fails

To: konrad.wilk@xxxxxxxxxx
Subject: [Xen-devel] [PATCH] xen-gntdev: Fix memory leak when mmap fails
From: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
Date: Thu, 3 Feb 2011 14:16:54 -0500
Cc: jeremy@xxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxx, Ian.Campbell@xxxxxxxxxx
Delivery-date: Thu, 03 Feb 2011 11:18:05 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1296753544-13323-1-git-send-email-dgdegra@xxxxxxxxxxxxx>
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>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.21 (2010-09-15)
Fix for a memory leak introduced in patch 3. Doesn't merge cleanly across
patch 4; I can post a corrected version of both patches if that would be
preferred.

------------------------------------------------------------->8

The error path did not decrement the reference count of the grant structure.

Signed-off-by: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
---
 drivers/xen/gntdev.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index 91706c2..6c754a9 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -649,15 +649,13 @@ static int gntdev_mmap(struct file *flip, struct 
vm_area_struct *vma)
                                          find_grant_ptes, map);
                if (err) {
                        printk(KERN_WARNING "find_grant_ptes() failure.\n");
-                       return err;
+                       goto out_put_map;
                }
        }
 
        err = map_grant_pages(map);
-       if (err) {
-               printk(KERN_WARNING "map_grant_pages() failure.\n");
-               return err;
-       }
+       if (err)
+               goto out_put_map;
 
        map->is_mapped = 1;
 
@@ -666,7 +664,7 @@ static int gntdev_mmap(struct file *flip, struct 
vm_area_struct *vma)
                        err = vm_insert_page(vma, vma->vm_start + i*PAGE_SIZE,
                                map->pages[i]);
                        if (err)
-                               return err;
+                               goto out_put_map;
                }
        }
 
@@ -675,6 +673,10 @@ static int gntdev_mmap(struct file *flip, struct 
vm_area_struct *vma)
 unlock_out:
        spin_unlock(&priv->lock);
        return err;
+
+out_put_map:
+       gntdev_put_map(map);
+       return err;
 }
 
 static const struct file_operations gntdev_fops = {
-- 
1.7.3.4


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

<Prev in Thread] Current Thread [Next in Thread>