Skip to contentSkip to conversation

nouveau/exa: unref bo if map failed

PATCH New Maarten Maathuis 1 participant 2 messages Jun 18, 2012 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 nouveau/exa: unref bo if map failed

---
 src/nouveau_exa.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
src/nouveau_exa.c +6 -2
index 55dce99..c51a799 100644
@@ -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;
 	}
Signature · 1 line
1.7.8.6
#2 lore raw

PATCH 2/2 nouveau/exa: Fix transfer bo memory leak

In reply to a message not in the archive

Thanks to "Christoph Bumiller <e0425955-oe7qfRrRQffzPE21tAIdciO7C/[email protected]>" for hinting at the cause of the problem.

---
 src/nouveau_exa.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
src/nouveau_exa.c +2 -0
index c51a799..bb946b6 100644
@@ -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;
 	}
 
Signature · 1 line
1.7.8.6