[PATCH 2/5] libkms/nouveau.c: Fix a memory leak and cleanup code a bit.

Johannes Obermayr johannesobermayr at gmx.de
Fri Jul 13 08:49:14 PDT 2012


---
 libkms/nouveau.c |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/libkms/nouveau.c b/libkms/nouveau.c
index 0e24a15..4cbca96 100644
--- a/libkms/nouveau.c
+++ b/libkms/nouveau.c
@@ -94,14 +94,18 @@ nouveau_bo_create(struct kms_driver *kms,
 	if (!bo)
 		return -ENOMEM;
 
-	if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8) {
+	switch (type) {
+	case KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8:
 		pitch = 64 * 4;
 		size = 64 * 64 * 4;
-	} else if (type == KMS_BO_TYPE_SCANOUT_X8R8G8B8) {
+		break;
+	case KMS_BO_TYPE_SCANOUT_X8R8G8B8:
 		pitch = width * 4;
 		pitch = (pitch + 512 - 1) & ~(512 - 1);
 		size = pitch * height;
-	} else {
+		break;
+	default:
+		free(bo);
 		return -EINVAL;
 	}
 
@@ -114,8 +118,10 @@ nouveau_bo_create(struct kms_driver *kms,
 	arg.channel_hint = 0;
 
 	ret = drmCommandWriteRead(kms->fd, DRM_NOUVEAU_GEM_NEW, &arg, sizeof(arg));
-	if (ret)
-		goto err_free;
+	if (ret) {
+		free(bo);
+		return ret;
+	}
 
 	bo->base.kms = kms;
 	bo->base.handle = arg.info.handle;
@@ -126,10 +132,6 @@ nouveau_bo_create(struct kms_driver *kms,
 	*out = &bo->base;
 
 	return 0;
-
-err_free:
-	free(bo);
-	return ret;
 }
 
 static int
-- 
1.7.7



More information about the dri-devel mailing list