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