From patchwork Fri Oct 16 22:11:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Roper X-Patchwork-Id: 7421211 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AB0BCBF90C for ; Fri, 16 Oct 2015 22:11:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E81B8208DD for ; Fri, 16 Oct 2015 22:11:35 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 684572061C for ; Fri, 16 Oct 2015 22:11:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6DEAD6E392; Fri, 16 Oct 2015 15:11:33 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id F38316E392 for ; Fri, 16 Oct 2015 15:11:31 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP; 16 Oct 2015 15:11:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,690,1437462000"; d="scan'208";a="582449660" Received: from mdroper-hswdev.fm.intel.com (HELO mdroper-hswdev) ([10.1.134.215]) by FMSMGA003.fm.intel.com with ESMTP; 16 Oct 2015 15:11:31 -0700 Received: from mattrope by mdroper-hswdev with local (Exim 4.84) (envelope-from ) id 1ZnDDn-0005Um-CP; Fri, 16 Oct 2015 15:11:31 -0700 From: Matt Roper To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 1/2] xf86drm: Fix error handling for drmGetDevice() Date: Fri, 16 Oct 2015 15:11:23 -0700 Message-Id: <1445033484-21089-1-git-send-email-matthew.d.roper@intel.com> X-Mailer: git-send-email 2.1.4 Cc: Emil Velikov 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some of the error conditions in drmGetDevice() can lead to us calling closedir(NULL) or leaking memory. Fix these conditions the same way we did for drmGetDevices() in commit: commit 8c4a1cbd98bd8d185d489395f33302a17db643a9 Author: Matt Roper Date: Wed Sep 30 09:30:51 2015 -0700 xf86drm: Fix error handling for drmGetDevices() Cc: Emil Velikov Signed-off-by: Matt Roper --- xf86drm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index a29db42..951edbb 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -3108,7 +3108,7 @@ int drmGetDevice(int fd, drmDevicePtr *device) sysdir = opendir(DRM_DIR_NAME); if (!sysdir) { ret = -errno; - goto close_sysdir; + goto free_locals; } i = 0; @@ -3165,16 +3165,16 @@ int drmGetDevice(int fd, drmDevicePtr *device) for (i = 1; i < node_count && local_devices[i]; i++) drmFreeDevice(&local_devices[i]); - free(local_devices); closedir(sysdir); + free(local_devices); return 0; free_devices: drmFreeDevices(local_devices, i); - free(local_devices); - -close_sysdir: closedir(sysdir); + +free_locals: + free(local_devices); return ret; }