From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965400AbcDLSGR (ORCPT ); Tue, 12 Apr 2016 14:06:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34469 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965083AbcDLSGQ (ORCPT ); Tue, 12 Apr 2016 14:06:16 -0400 Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <1460463119-8409-1-git-send-email-sudipm.mukherjee@gmail.com> References: <1460463119-8409-1-git-send-email-sudipm.mukherjee@gmail.com> To: Sudip Mukherjee Cc: dhowells@redhat.com, linux-kernel@vger.kernel.org, mkayaalp@linux.vnet.ibm.com Subject: Re: [PATCH] KEYS: fix memory leak MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <32126.1460484373.1@warthog.procyon.org.uk> Date: Tue, 12 Apr 2016 19:06:13 +0100 Message-ID: <32127.1460484373@warthog.procyon.org.uk> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sudip Mukherjee wrote: > If the file read fails then we returned NULL as error but we missed > freeing buf. It's not a particularly critical error since it's a build-time script rather than the kernel. Possibly read_file() and map_file() should just exit upon encountering an error rather than returning. David > diff --git a/scripts/insert-sys-cert.c b/scripts/insert-sys-cert.c > index 8902836..b98a0b1 100644 > --- a/scripts/insert-sys-cert.c > +++ b/scripts/insert-sys-cert.c > @@ -251,6 +251,7 @@ static char *read_file(char *file_name, int *size) > if (read(fd, buf, *size) != *size) { > perror("File read failed"); > close(fd); > + free(buf); > return NULL; > } > close(fd);