Re: [ILUG] C question [puzzled by strdup()]

From: John P. Looney (john at domain antefacto.com)
Date: Thu 02 Aug 2001 - 10:32:57 IST


On Thu, Aug 02, 2001 at 12:06:47AM +0100, Conor Daly mentioned:
> The first call to strdup() allocates memory to hold the string and sets
> optionstring to that address. When the second strdup() call passes a
> *new* address to optionstring, what happens the previously allocated
> memory that optionstring *was* pointing to?

 No offense Conor, but I strongly recommend you stick to Perl, Shell, TCL
or Java! Something that'll do your garbage collection for you.

 In the manpage for strdup, there is;

        "Memory for the new string is obtained with mal­ loc(3), and can
         be freed with free(3)"

 It should read "For crying out loud, free this as soon as you can, or
you'll be reaching for ElectricFence within a week".

Kate

-- 
When I say 'free', I mean 'free': free from bond, of chain or command:
to go where you will, even to Mordor, Saruman, if you desire. "
    -- Gandalf, paraphrasing the choice between Free and Non-free software


This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:11:26 GMT