[Nut-upsdev] [nut-commits] svn commit r2845 - branches/windows_port/common
Frédéric Bohé
fredericbohe at eaton.com
Wed Jan 19 10:39:01 UTC 2011
On mer., 2011-01-19 at 09:12 +0100, Arjen de Korte wrote:
> Citeren Frédéric Bohé <fredericbohe at 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.
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
--------------------------------------------------------------------------
More information about the Nut-upsdev
mailing list