From patchwork Mon Mar 27 02:09:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Seung-Woo Kim X-Patchwork-Id: 9645255 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 2EA9C601D7 for ; Mon, 27 Mar 2017 02:09:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15A94283F2 for ; Mon, 27 Mar 2017 02:09:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0959D283FB; Mon, 27 Mar 2017 02:09:19 +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 2A2D8283F2 for ; Mon, 27 Mar 2017 02:09:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8D5886E138; Mon, 27 Mar 2017 02:09:15 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from epoutp02.samsung.com (mailout2.samsung.com [203.254.224.25]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4C4666E138 for ; Mon, 27 Mar 2017 02:09:14 +0000 (UTC) Received: from epcas1p4.samsung.com (unknown [182.195.41.48]) by epoutp02.samsung.com (KnoxPortal) with ESMTP id 20170327020912epoutp02ed111fa4bae348ac64415e3a74c72ca2~vmx1i8yrg1051310513epoutp02k; Mon, 27 Mar 2017 02:09:12 +0000 (GMT) Received: from epsmges5p5.samsung.com (unknown [182.195.40.69]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20170327020911epcas1p4ec2d77e0b7857427998784038d0dbd9d~vmx1SqV8F0452004520epcas1p49; Mon, 27 Mar 2017 02:09:11 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmges5p5.samsung.com (EPCPMTA) with SMTP id C5.E5.06094.74478D85; Mon, 27 Mar 2017 11:09:11 +0900 (KST) Received: from epcpsbgm2new.samsung.com (u27.gpu120.samsung.co.kr [203.254.230.27]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20170327020910epcas5p3dcc43c4f22f2d6d2edf35568920eebfd~vmxz04amU1618216182epcas5p3H; Mon, 27 Mar 2017 02:09:10 +0000 (GMT) X-AuditID: b6c32a59-f79166d0000017ce-6e-58d87447ce10 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id 31.C2.05013.64478D85; Mon, 27 Mar 2017 11:09:10 +0900 (KST) Received: from localhost.localdomain ([10.113.62.209]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0ONG00FP6BB8NW00@mmp2.samsung.com>; Mon, 27 Mar 2017 11:09:10 +0900 (KST) From: Seung-Woo Kim To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm] xf86drm: remove memory leaks in drmGetBusid/drmGetReservedContextList Date: Mon, 27 Mar 2017 11:09:29 +0900 Message-id: <1490580569-5167-1-git-send-email-sw0312.kim@samsung.com> X-Mailer: git-send-email 1.7.4.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprDKsWRmVeSWpSXmKPExsWy7bCmlq57yY0Ig2WvTC2ufH3PZrHn6j0m ixf3LrJYzJj8ks2BxWPnrLvsHve7jzN59G1ZxRjAHJVqk5GamJJapJCal5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6dgluGcvn/mYqmMZb8WbOPuYGxi+c XYycHBICJhLP3t9ghrDFJC7cW8/WxcjFISQwi1FixrPZUM4PRon/S5vYQKrYBHQk9i/5zQpi iwgoS/yduIoRxGYW8JV4fn8C2CRhgXiJPduPsIPYLAKqEqvW/Aar4RVwlei6coMJYpuCxIJ7 b9kmMHIvYGRYxSiRWpBcUJyUnmuUl1quV5yYW1yal66XnJ+7iREcdM+kdzAe3uV+iFGAg1GJ h3eH2I0IIdbEsuLK3EOMEhzMSiK8u1mAQrwpiZVVqUX58UWlOanFhxhNgQ6YyCwlmpwPjIi8 knhDE3MTc2MDC3NLSxMjJXHextnPwoUE0hNLUrNTUwtSi2D6mDg4pRoY7SZxtRktzbzXcmWn TtbEhq/nd7078Fft480gORH7zbK/V+1gNl/BfdtFye7v2xRnr3drqw2Ejt+boDZ9enaXyKXk gzUPDsrcKpZcVaewreua6ZUDvyrCki49dz6sxcdk37V0RobuOedHzpOlX2os+1i76dz2q985 jwrGX5x71zT6g/IVRsaIACWW4oxEQy3mouJEALG2JeZQAgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170327020910epcas5p3dcc43c4f22f2d6d2edf35568920eebfd X-Msg-Generator: CA X-Sender-IP: 203.254.230.27 X-Local-Sender: =?UTF-8?B?6rmA7Iq57JqwG1RpemVuIFBsYXRmb3JtIExhYihTL1fshLw=?= =?UTF-8?B?7YSwKRvsgrzshLHsoITsnpAbU2VuaW9yIEVuZ2luZWVy?= X-Global-Sender: =?UTF-8?B?U2V1bmctV29vIEtpbRtUaXplbiBQbGF0Zm9ybSBMYWIuG1Nh?= =?UTF-8?B?bXN1bmcgRWxlY3Ryb25pY3MbU2VuaW9yIEVuZ2luZWVy?= X-Sender-Code: =?UTF-8?B?QzEwG1NUQUYbQzEwVjgxMTE=?= CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20170327020910epcas5p3dcc43c4f22f2d6d2edf35568920eebfd X-RootMTR: 20170327020910epcas5p3dcc43c4f22f2d6d2edf35568920eebfd References: Cc: sw0312.kim@samsung.com, emil.l.velikov@gmail.com 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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP In error path of drmGetBusid() and drmGetReservedContextList(), there are memory leaks for error path. So this removes them. Signed-off-by: Seung-Woo Kim Reviewed-by: Nicolai Hähnle --- xf86drm.c | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index 88f86ed..685cf69 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -994,8 +994,10 @@ char *drmGetBusid(int fd) if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) return NULL; u.unique = drmMalloc(u.unique_len + 1); - if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) + if (drmIoctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) { + drmFree(u.unique); return NULL; + } u.unique[u.unique_len] = '\0'; return u.unique; @@ -1523,14 +1525,12 @@ drm_context_t *drmGetReservedContextList(int fd, int *count) if (!(list = drmMalloc(res.count * sizeof(*list)))) return NULL; - if (!(retval = drmMalloc(res.count * sizeof(*retval)))) { - drmFree(list); - return NULL; - } + if (!(retval = drmMalloc(res.count * sizeof(*retval)))) + goto err_free_list; res.contexts = list; if (drmIoctl(fd, DRM_IOCTL_RES_CTX, &res)) - return NULL; + goto err_free_context; for (i = 0; i < res.count; i++) retval[i] = list[i].handle; @@ -1538,6 +1538,12 @@ drm_context_t *drmGetReservedContextList(int fd, int *count) *count = res.count; return retval; + +err_free_list: + drmFree(list); +err_free_context: + drmFree(retval); + return NULL; } void drmFreeReservedContextList(drm_context_t *pt)