[Nut-upsdev] [nut-commits] svn commit r2845 - branches/windows_port/common

Arjen de Korte nut+devel at de-korte.org
Wed Jan 19 08:12:54 UTC 2011


Citeren Frédéric Bohé <fredericbohe op eaton.com>:

>> +	static const char *path = getfullpath(PATH_ETC);
>
> getfullpath is allocating memory with xstrdup. Doesn't this line produce
> a memory leak ?

Nope.

Whenever you do an assignment to a static variable, this is only done  
once. So the getfullpath() function will be called the first time you  
enter this function and afterwards, the result of this call will be  
used. Unlike an ordinary automatic variable, static variables defined  
in functions are preserved between calls.

We usually prefer static local variables over global ones, because it  
prevents namespace conflicts and also prevents other function from  
messing with the variables.

Best regards, Arjen
-- 
Please keep list traffic on the list (off-list replies will be rejected)




More information about the Nut-upsdev mailing list