From: Eric Engestrom <eric.engestrom@imgtec.com>
To: Seung-Woo Kim <sw0312.kim@samsung.com>
Cc: emil.l.velikov@gmail.com, robclark@freedesktop.org,
dri-devel@lists.freedesktop.org
Subject: Re: [RESEND][PATCH] libkms/exynos: fix memory leak in error path
Date: Wed, 14 Dec 2016 12:07:42 +0000 [thread overview]
Message-ID: <20161214120742.GH29253@imgtec.com> (raw)
In-Reply-To: <1481703390-30045-1-git-send-email-sw0312.kim@samsung.com>
On Wednesday, 2016-12-14 17:16:30 +0900, Seung-Woo Kim wrote:
> This patch fixes memory leak in error path of exynos_bo_create().
Indeed, thanks!
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
>
> Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
> ---
> libkms/exynos.c | 3 ++-
> 1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/libkms/exynos.c b/libkms/exynos.c
> index 5de2e5a..0e97fb5 100644
> --- a/libkms/exynos.c
> +++ b/libkms/exynos.c
> @@ -88,7 +88,8 @@ exynos_bo_create(struct kms_driver *kms,
> pitch = (pitch + 512 - 1) & ~(512 - 1);
> size = pitch * ((height + 4 - 1) & ~(4 - 1));
> } else {
> - return -EINVAL;
> + ret = -EINVAL;
> + goto err_free;
> }
>
> memset(&arg, 0, sizeof(arg));
> --
> 1.7.4.1
>
However, I feel like a cleaner fix might be to simply move the
allocation to where it's used and remove the now-unnecessary
error path, ie.:
----8<----
diff --git a/libkms/exynos.c b/libkms/exynos.c
index 5de2e5a..e2c1c9f 100644
--- a/libkms/exynos.c
+++ b/libkms/exynos.c
@@ -76,10 +76,6 @@ exynos_bo_create(struct kms_driver *kms,
}
}
- bo = calloc(1, sizeof(*bo));
- if (!bo)
- return -ENOMEM;
-
if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8) {
pitch = 64 * 4;
size = 64 * 64 * 4;
@@ -96,7 +92,11 @@ exynos_bo_create(struct kms_driver *kms,
ret = drmCommandWriteRead(kms->fd, DRM_EXYNOS_GEM_CREATE, &arg, sizeof(arg));
if (ret)
- goto err_free;
+ return ret;
+
+ bo = calloc(1, sizeof(*bo));
+ if (!bo)
+ return -ENOMEM;
bo->base.kms = kms;
bo->base.handle = arg.handle;
@@ -106,10 +106,6 @@ exynos_bo_create(struct kms_driver *kms,
*out = &bo->base;
return 0;
-
-err_free:
- free(bo);
- return ret;
}
static int
---->8----
Bigger change, but cleaner code IMHO.
What do you think?
Cheers,
Eric
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2016-12-14 12:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-14 5:31 [PATCH libdrm] libkms/exynos: fix memory leak in error path Seung-Woo Kim
2016-12-14 8:16 ` [RESEND][PATCH] " Seung-Woo Kim
2016-12-14 12:07 ` Eric Engestrom [this message]
2016-12-14 12:21 ` Emil Velikov
2016-12-14 13:12 ` Eric Engestrom
2016-12-14 17:12 ` Emil Velikov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161214120742.GH29253@imgtec.com \
--to=eric.engestrom@imgtec.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=emil.l.velikov@gmail.com \
--cc=robclark@freedesktop.org \
--cc=sw0312.kim@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.