Ahhh! Shades of the evil empire! Must avoid leaks at all costs. Actually,
I should have realized this myself. Thanks Glynn.

Joe.

(I've got to stop programming when I'm tired....)

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
| Joseph Martin:        |      [EMAIL PROTECTED]           |
| Amateur C Programmer, |      http://users.exis.net/~jam/ |
| Web Designer,         |                                  |
| All around tech nut   |                                  |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

On Mon, 6 Jul 1998, Glynn Clements wrote:

> 
> Joseph Martin wrote:
> 
> > Okay. I have a class that the constructor sets default string values using
> > strdup to copy the strings into the variables. This is mainly so that the
> > destructor can call free for each variable without worrying about freeing
> > unitialized memory. However, what happens when strdup is used a second
> > time? i.e. the first statement is name = strdup( "Joseph" ) and the second
> > statement is name = strdup( "Martin" ). What happens to the orginal memory
> > name pointed to? Is it freed? Is it left there? What do I need to do (if
> > anything)?
> 
> You need to call `free(name)' before the second `name = strdup(...)'. 
> Otherwise your program will leak memory.
> 
> -- 
> Glynn Clements <[EMAIL PROTECTED]>
> 

Reply via email to