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

Frédéric Bohé fredericbohe at eaton.com
Wed Jan 19 07:47:09 UTC 2011


On mar., 2011-01-18 at 19:52 +0000, Arjen de Korte wrote:
> Author: adkorte-guest
> Date: Tue Jan 18 19:52:02 2011
> New Revision: 2845
> URL: http://trac.networkupstools.org/projects/nut/changeset/2845
> 
> Log:
> Prefer to use static variables locally over global variables (to prevent namespace conflicts)
> 
> Modified:
>    branches/windows_port/common/common.c
> 
> Modified: branches/windows_port/common/common.c
> ==============================================================================
> --- branches/windows_port/common/common.c	Tue Jan 18 15:40:58 2011	(r2844)
> +++ branches/windows_port/common/common.c	Tue Jan 18 19:52:02 2011	(r2845)
> @@ -41,11 +41,6 @@
>  	int	nut_log_level = 0;
>  	static	int	upslog_flags = UPSLOG_STDERR;
>  
> -#ifdef WIN32
> -const char * relative_conf_path = NULL;
> -const char * relative_state_path = NULL;
> -#endif
> -
>  static void xbit_set(int *val, int flag)
>  {
>  	*val |= flag;
> @@ -440,51 +435,25 @@
>  
> 
>  /* Return the default path for the directory containing configuration files */
> -const char * confpath(void) 
> +const char * confpath(void)
>  {
> -	const char * path;
> -
> -	if ((path = getenv("NUT_CONFPATH")) == NULL) {
>  #ifndef WIN32
> -		path = CONFPATH;
> +	const char *path = getenv("NUT_CONFPATH");
>  #else
> -		if( relative_conf_path == NULL ) {
> -			path = getfullpath(PATH_ETC);
> -			if( path == NULL ) {
> -				path = CONFPATH;
> -			}
> -		}
> -		else {
> -			path = relative_conf_path;
> -		}
> +	static const char *path = getfullpath(PATH_ETC);

getfullpath is allocating memory with xstrdup. Doesn't this line produce
a memory leak ?



>  #endif
> -	}
> -
> -	return path;
> +	return (path != NULL) ? path : CONFPATH;
>  }
>  
>  /* Return the default path for the directory containing state files */
> -const char * dflt_statepath(void) 
> +const char * dflt_statepath(void)
>  {
> -	const char * path;
> -
> -	if ((path = getenv("NUT_STATEPATH")) == NULL) {
>  #ifndef WIN32
> -		path = STATEPATH;
> +	const char *path = getenv("NUT_STATEPATH");
>  #else
> -		if( relative_state_path == NULL ) {
> -			path = getfullpath(PATH_VAR_RUN);
> -			if( path == NULL ) {
> -				path = STATEPATH;
> -			}
> -		}
> -		else {
> -			path = relative_state_path;
> -		}
> +	static const char *path = getfullpath(PATH_VAR_RUN);
>  #endif
> -	}
> -
> -	return path;
> +	return (path != NULL) ? path : STATEPATH;
>  }
>  
>  /* Return the alternate path for pid files */
> 
> _______________________________________________
> nut-commits mailing list
> nut-commits at lists.alioth.debian.org
> http://lists.alioth.debian.org/mailman/listinfo/nut-commits


--------------------------------------------------------------------------



More information about the Nut-upsdev mailing list