From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 53F96210ED104 for ; Fri, 10 Aug 2018 17:40:59 -0700 (PDT) From: Vishal Verma Subject: [ndctl PATCH 2/2] ndctl, udev: fix a resource leak in save_unsafe_shutdown_count Date: Fri, 10 Aug 2018 18:40:53 -0600 Message-Id: <20180811004053.15392-2-vishal.l.verma@intel.com> In-Reply-To: <20180811004053.15392-1-vishal.l.verma@intel.com> References: <20180811004053.15392-1-vishal.l.verma@intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" To: linux-nvdimm@lists.01.org List-ID: Static analysis reports that we leak the 'fd' in the above function. Fix by adding a proper cleanup path that closes it. Cc: Keith Busch Fixes: dd8e6ff9ab00 ("ndctl: Create ndctl udev rules for dirty shutdown") Signed-off-by: Vishal Verma --- ndctl/ndctl-udev.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ndctl/ndctl-udev.c b/ndctl/ndctl-udev.c index 2b4d067..7b174b6 100644 --- a/ndctl/ndctl-udev.c +++ b/ndctl/ndctl-udev.c @@ -110,10 +110,13 @@ static void save_unsafe_shutdown_count(struct ndctl_dimm *dimm, goto free_usc; if (snprintf(count, sizeof(count), "%u\n", shutdown) < 0) - goto free_usc; + goto close_fd; if (write(fd, count, strlen(count)) < 0) - goto free_usc; + goto close_fd; + + close_fd: + close(fd); free_usc: free(usc); free_path: -- 2.14.4 _______________________________________________ Linux-nvdimm mailing list Linux-nvdimm@lists.01.org https://lists.01.org/mailman/listinfo/linux-nvdimm