Maarten Maathuis
2012-Jun-18  22:28 UTC
[Nouveau] [PATCH 1/2] nouveau/exa: unref bo if map failed
Signed-off-by: Maarten Maathuis <madman2003 at gmail.com>
---
 src/nouveau_exa.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/nouveau_exa.c b/src/nouveau_exa.c
index 55dce99..c51a799 100644
--- a/src/nouveau_exa.c
+++ b/src/nouveau_exa.c
@@ -175,11 +175,15 @@ nouveau_exa_scratch(NVPtr pNv, int size, struct nouveau_bo
**pbo, int *off)
 		ret = nouveau_bo_new(pNv->dev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP,
 				     0, NOUVEAU_ALIGN(size, 1 * 1024 * 1024),
 				     NULL, &bo);
-		if (ret == 0)
-			ret = nouveau_bo_map(bo, NOUVEAU_BO_RDWR, pNv->client);
 		if (ret != 0)
 			return ret;
 
+		ret = nouveau_bo_map(bo, NOUVEAU_BO_RDWR, pNv->client);
+		if (ret != 0) {
+			nouveau_bo_ref(NULL, &bo);
+			return ret;
+		}
+
 		nouveau_bo_ref(bo, &pNv->transfer);
 		pNv->transfer_offset = 0;
 	}
-- 
1.7.8.6
Maarten Maathuis
2012-Jun-18  22:29 UTC
[Nouveau] [PATCH 2/2] nouveau/exa: Fix transfer bo memory leak
Thanks to "Christoph Bumiller <e0425955 at student.tuwien.ac.at>" for hinting at the cause of the problem. Signed-off-by: Maarten Maathuis <madman2003 at gmail.com> --- src/nouveau_exa.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/src/nouveau_exa.c b/src/nouveau_exa.c index c51a799..bb946b6 100644 --- a/src/nouveau_exa.c +++ b/src/nouveau_exa.c @@ -185,6 +185,8 @@ nouveau_exa_scratch(NVPtr pNv, int size, struct nouveau_bo **pbo, int *off) } nouveau_bo_ref(bo, &pNv->transfer); + /* Lower the refcount of the bo back to 1, otherwise it will never be freed. */ + nouveau_bo_ref(NULL, &bo); pNv->transfer_offset = 0; } -- 1.7.8.6