Citeren Frédéric Bohé <[email protected]>:

+       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)


_______________________________________________
Nut-upsdev mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/nut-upsdev

Reply via email to