[PATCH 1/6] libkms/intel.c: Fix a memory leak and a dead assignment as well as make some code easier to read.
Johannes Obermayr
johannesobermayr at gmx.de
Fri Jul 13 11:34:21 PDT 2012
---
libkms/intel.c | 32 +++++++++++++++++---------------
1 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/libkms/intel.c b/libkms/intel.c
index 8b8249b..12175b0 100644
--- a/libkms/intel.c
+++ b/libkms/intel.c
@@ -89,27 +89,32 @@ intel_bo_create(struct kms_driver *kms,
}
}
- bo = calloc(1, sizeof(*bo));
- 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 + 4 - 1) & ~(4 - 1));
- } else {
+ break;
+ default:
return -EINVAL;
}
+ bo = calloc(1, sizeof(*bo));
+ if (!bo)
+ return -ENOMEM;
+
memset(&arg, 0, sizeof(arg));
arg.size = size;
ret = drmCommandWriteRead(kms->fd, DRM_I915_GEM_CREATE, &arg, sizeof(arg));
- if (ret)
- goto err_free;
+ if (ret) {
+ free(bo);
+ return ret;
+ }
bo->base.kms = kms;
bo->base.handle = arg.handle;
@@ -124,21 +129,18 @@ intel_bo_create(struct kms_driver *kms,
tile.handle = bo->base.handle;
tile.tiling_mode = I915_TILING_X;
tile.stride = bo->base.pitch;
-
- ret = drmCommandWriteRead(kms->fd, DRM_I915_GEM_SET_TILING, &tile, sizeof(tile));
#if 0
+ ret = drmCommandWriteRead(kms->fd, DRM_I915_GEM_SET_TILING, &tile, sizeof(tile));
if (ret) {
kms_bo_destroy(out);
return ret;
}
+#else
+ drmCommandWriteRead(kms->fd, DRM_I915_GEM_SET_TILING, &tile, sizeof(tile));
#endif
}
return 0;
-
-err_free:
- free(bo);
- return ret;
}
static int
--
1.7.7
More information about the dri-devel
mailing list