www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2002/01/05/12:31:12

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-workers-bounces using -f
From: "Tim Van Holder" <tim DOT van DOT holder AT pandora DOT be>
To: <djgpp-workers AT delorie DOT com>,
"'Richard Dawe'" <rich AT phekda DOT freeserve DOT co DOT uk>
Subject: Re: Memory leaks fixes
Date: Sat, 5 Jan 2002 18:31:01 +0100
Message-ID: <000001c1960e$bf2c61f0$cef8e0d5@zastaixp>
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook, Build 10.0.3416
In-reply-to: <6551-Sat05Jan2002163435+0200-eliz@is.elta.co.il>
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> > -    if (fsext_list == 0)
> > +    temp = (__FSEXT_entry *)realloc(fsext_list, num_fds * 
> sizeof(__FSEXT_entry));
> > +    if (temp == 0)
> > +    {
> 
> Why do you only call realloc if fsext_list is NULL?  AFAICS, it

He doesn't; the if (fsext_list) is from the old file (hence the '-').

> >    *d = '\0';
> > -  /* Free unused space.  */
> > -  cmd->command = (char *) realloc (cmd->command, cmd_len + 1);
> > +  /* Free unused space, if we can.  */
> > +  d = (char *) realloc (cmd->command, cmd_len + 1);
> > +  if (d)
> > +    cmd->command = d;
> 
> No, please don't!  This code compacts the string, and thus the result
> will always be _smaller_ than the original.  So if realloc fails here,
> the right thing to do would be to return the original string.

Which is what happens - instead of losing the original pointer (which
is what the old code did), it now puts in the pointer returned by
realloc only if it wasn't NULL; otherwise cmd->command remains
unchanged.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019