LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] C string concat question revisited

[ILUG] C string concat question revisited

Conor Daly conor.daly at oceanfree.net
Thu Jul 5 09:24:07 IST 2001


On Wed, Jul 04, 2001 at 10:16:47AM +0100 or so it is rumoured hereabouts, 
Dave Neary thought:
> Conor Daly wrote:
> > 
> > >   if (my_buf)
> > >   {
> > >     char *tmp = realloc(my_buf, strlen(my_buf) +
> > >                         strlen(next_string) + 1);

The only question left here is:

Does 'tmp = realloc(my_buf,<size>);' free the block pointed to by my_buf
while returning the address of the new block into tmp?

> > >     if(tmp == NULL)
> > >     {
> > >       fprintf(stderr, "realloc failed - not modifying my_buf\n");
> > >     }
> > >     else
> > >     {
> > >       my_buf = tmp;
> >         ^^^^^^^^^^^^^

Otherwise, this becomes a memory leak.

> > >       strncat(my_buf, next_string, strlen(next_string)+1);
> > >     }   
> > >   }
> > > else /* The rest looked OK */

Conor
-- 
Conor Daly <conor.daly at oceanfree.net>

Domestic Sysadmin :-)
---------------------
Faenor.cod.ie
  9:01am  up 20 days,  9:18,  0 users,  load average: 0.08, 0.02, 0.01
Hobbiton.cod.ie
  9:09am  up 20 days,  9:27,  1 user,  load average: 0.04, 0.02, 0.00




More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell