From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH 1/2] Fix memory leak on `realloc' failure Date: Thu, 10 Apr 2014 12:36:48 -0400 Message-ID: <20140410163648.MIXO2.198633.root@cdptpa-web07> References: <1397108266-18581-1-git-send-email-KAction@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1397147839 6190 80.91.229.3 (10 Apr 2014 16:37:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 10 Apr 2014 16:37:19 +0000 (UTC) To: guile-devel@gnu.org, KAction@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Apr 10 18:37:11 2014 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WYHyR-0008Ur-D1 for guile-devel@m.gmane.org; Thu, 10 Apr 2014 18:37:11 +0200 Original-Received: from localhost ([::1]:53293 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYHyR-0001o9-0f for guile-devel@m.gmane.org; Thu, 10 Apr 2014 12:37:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYHyE-0001eD-Cp for guile-devel@gnu.org; Thu, 10 Apr 2014 12:37:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WYHy6-0002Zk-4J for guile-devel@gnu.org; Thu, 10 Apr 2014 12:36:58 -0400 Original-Received: from cdptpa-outbound-snat.email.rr.com ([107.14.166.227]:5553 helo=cdptpa-oedge-vip.email.rr.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYHy6-0002Yt-0j for guile-devel@gnu.org; Thu, 10 Apr 2014 12:36:50 -0400 Authentication-Results: cdptpa-oedge01 smtp.user=dsmich@roadrunner.com; auth=pass (LOGIN) Original-Received: from [107.14.174.248] ([107.14.174.248:2696] helo=cdptpa-web07) by cdptpa-oedge01 (envelope-from ) (ecelerity 3.5.0.35861 r(Momo-dev:tip)) with ESMTPA id 0D/AC-00399-0A8C6435; Thu, 10 Apr 2014 16:36:48 +0000 In-Reply-To: <1397108266-18581-1-git-send-email-KAction@gnu.org> X-Priority: 3 (Normal) Sensitivity: Normal X-Originating-IP: from 66.178.229.165 by webmail.roadrunner.com; Thu, 10 Apr 2014 16:36:48 +0000 X-RR-Connecting-IP: 107.14.168.118:2525 X-Cloudmark-Score: 0 X-detected-operating-system: by eggs.gnu.org: BaiduSpider X-Received-From: 107.14.166.227 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:17048 Archived-At: ---- KAction@gnu.org wrote: > From: Dmitry Bogatov > > Signed-off-by: Dmitry Bogatov > --- > libguile/script.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/libguile/script.c b/libguile/script.c > index 052ab8d..7b737f7 100644 > --- a/libguile/script.c > +++ b/libguile/script.c > @@ -247,7 +247,10 @@ script_read_arg (FILE *f) > size = (size + 1) * 2; > buf = realloc (buf, size); > if (! buf) > - return 0; > + { > + free (buf); > + return 0; > + } > } > buf[len++] = c; > break; > @@ -330,7 +333,10 @@ scm_get_meta_args (int argc, char **argv) > while ((narg = script_read_arg (f))) > if (!(nargv = (char **) realloc (nargv, > (1 + ++nargc) * sizeof (char *)))) > + { > + free (nargv); > return 0L; > + } > else > nargv[nargi++] = narg; > fclose (f); I don't understand this. In both cases, free() will be called with an argument of 0, which does nothing. -Dale