On mer., 2011-01-19 at 09:12 +0100, Arjen de Korte wrote: > 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.
Thanks for the clarification. I just tried to compile and I have an error on this line, not sure how to fix that. common.c: In function 'confpath': common.c:443:2: error: initializer element is not constant common.c: In function 'dflt_statepath': common.c:454:2: error: initializer element is not constant -------------------------------------------------------------------------- _______________________________________________ Nut-upsdev mailing list [email protected] http://lists.alioth.debian.org/mailman/listinfo/nut-upsdev
