From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Bogatov Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH 1/2] Fix memory leak on `realloc' failure Date: Thu, 10 Apr 2014 20:52:43 +0400 Organization: Church of GNU Message-ID: <20140410165243.GA16599@localhost.kaction.name> References: <1397108266-18581-1-git-send-email-KAction@gnu.org> <20140410163648.MIXO2.198633.root@cdptpa-web07> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1397148788 23048 80.91.229.3 (10 Apr 2014 16:53:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 10 Apr 2014 16:53:08 +0000 (UTC) Cc: guile-devel@gnu.org To: dsmich@roadrunner.com Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Apr 10 18:53:03 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 1WYIDm-0005V2-2Y for guile-devel@m.gmane.org; Thu, 10 Apr 2014 18:53:02 +0200 Original-Received: from localhost ([::1]:53374 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYIDl-0002D3-Gv for guile-devel@m.gmane.org; Thu, 10 Apr 2014 12:53:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50963) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYIDe-0002C3-5x for guile-devel@gnu.org; Thu, 10 Apr 2014 12:52:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WYIDZ-00085m-Hm for guile-devel@gnu.org; Thu, 10 Apr 2014 12:52:54 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:46811) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYIDZ-00085i-EM for guile-devel@gnu.org; Thu, 10 Apr 2014 12:52:49 -0400 Original-Received: from [195.154.167.241] (port=57476 helo=localhost) by fencepost.gnu.org with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1WYIDY-0004IQ-KT; Thu, 10 Apr 2014 12:52:49 -0400 Content-Disposition: inline In-Reply-To: <20140410163648.MIXO2.198633.root@cdptpa-web07> X-Haskell-Quote: IO String contains a String in the same way that /bin/ls contains a list of files X-Perfect-World: There should be one -- and preferably only one -- obvious way to do it. User-Agent: Mutt/1.5.23 (2014-03-12) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::e 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:17049 Archived-At: * dsmich@roadrunner.com [2014-04-10 12:36:48-0400] > > + { > > + free (nargv); > > return 0L; > > + } > > else > > nargv[nargi++] = narg; > I don't understand this. In both cases, free() will be called with an > argument of 0, which does nothing. My bad. It does not fix problem, that if realloc fails, it does not free memory, but we blindly assign, losing pointer to previous memory chunk. I will make another patch, like this void* xrealloc(void *old_ptr, size_t new_size) { void *new_ptr = realloc(old_ptr, new_size); if (!new_ptr) free(old_ptr); return new_ptr; } Suggestions, maybe more conventional name? -- Best regards, Dmitry Bogatov , Free Software supporter, esperantisto and netiquette guardian. git://kaction.name/rc-files.git GPG: 54B7F00D