unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: <dsmich@roadrunner.com>
To: guile-devel@gnu.org, KAction@gnu.org
Subject: Re: [PATCH 1/2] Fix memory leak on `realloc' failure
Date: Thu, 10 Apr 2014 12:36:48 -0400	[thread overview]
Message-ID: <20140410163648.MIXO2.198633.root@cdptpa-web07> (raw)
In-Reply-To: <1397108266-18581-1-git-send-email-KAction@gnu.org>


---- KAction@gnu.org wrote: 
> From: Dmitry Bogatov <KAction@gnu.org>
> 
> Signed-off-by: Dmitry Bogatov <KAction@gnu.org>
> ---
>  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






  parent reply	other threads:[~2014-04-10 16:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-10  5:37 [PATCH 1/2] Fix memory leak on `realloc' failure KAction
2014-04-10  5:37 ` [PATCH 2/2] Reduce scope of variables KAction
2014-04-10 16:36 ` dsmich [this message]
2014-04-10 16:52   ` [PATCH 1/2] Fix memory leak on `realloc' failure Dmitry Bogatov
2014-04-12  6:59     ` Dmitry Bogatov
2014-04-22 20:25       ` Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140410163648.MIXO2.198633.root@cdptpa-web07 \
    --to=dsmich@roadrunner.com \
    --cc=KAction@gnu.org \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).