From patchwork Wed Dec 14 12:07:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Engestrom X-Patchwork-Id: 9474103 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 55B88607EE for ; Wed, 14 Dec 2016 12:07:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DB4028611 for ; Wed, 14 Dec 2016 12:07:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2103C28697; Wed, 14 Dec 2016 12:07:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0D2D828611 for ; Wed, 14 Dec 2016 12:07:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2E3086E7CF; Wed, 14 Dec 2016 12:07:46 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailapp01.imgtec.com (mailapp01.imgtec.com [195.59.15.196]) by gabe.freedesktop.org (Postfix) with ESMTP id C79E66E7CF for ; Wed, 14 Dec 2016 12:07:44 +0000 (UTC) Received: from HHMAIL01.hh.imgtec.org (unknown [10.100.10.19]) by Forcepoint Email with ESMTPS id 84D336BBE59D7; Wed, 14 Dec 2016 12:07:40 +0000 (GMT) Received: from imgtec.com (10.60.4.28) by HHMAIL01.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Wed, 14 Dec 2016 12:07:42 +0000 Date: Wed, 14 Dec 2016 12:07:42 +0000 From: Eric Engestrom To: Seung-Woo Kim Subject: Re: [RESEND][PATCH] libkms/exynos: fix memory leak in error path Message-ID: <20161214120742.GH29253@imgtec.com> References: <1479101494-12007-1-git-send-email-sw0312.kim@samsung.com> <1481703390-30045-1-git-send-email-sw0312.kim@samsung.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1481703390-30045-1-git-send-email-sw0312.kim@samsung.com> User-Agent: Mutt/1.7.2 (2016-11-26) X-Originating-IP: [10.60.4.28] Cc: emil.l.velikov@gmail.com, robclark@freedesktop.org, dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 > > Signed-off-by: Seung-Woo Kim > --- > 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<---- ---->8---- Bigger change, but cleaner code IMHO. What do you think? Cheers, Eric 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