[PATCH] Fix segfault when there's no config dir

walter harms wharms at bfs.de
Mon Nov 28 08:14:43 PST 2011



Am 28.11.2011 17:09, schrieb przanoni at gmail.com:
> From: Paulo Zanoni <paulo.r.zanoni at intel.com>
> 
> Also, call AddConfigDirFiles only if we found a file, protecting
> ourselves from future changes to the AddConfigDirFiles function.
> 
> Signed-off-by: Paulo Zanoni <paulo.r.zanoni at intel.com>
> ---
>  hw/xfree86/parser/scan.c |    9 ++++++---
>  1 files changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c
> index 9099227..54fa474 100644
> --- a/hw/xfree86/parser/scan.c
> +++ b/hw/xfree86/parser/scan.c
> @@ -852,13 +852,16 @@ OpenConfigDir(const char *path, const char *cmdline, const char *projroot,
>  
>  		/* match files named *.conf */
>  		num = scandir(dirpath, &list, ConfigFilter, alphasort);
> -		found = AddConfigDirFiles(dirpath, list, num);
> +		if (num > 0)
> +			found = AddConfigDirFiles(dirpath, list, num);
> +		else
> +			found = FALSE;

looks ok, perhaps it is the better strategy to make AddConfigDirFiles() more robust by checking num ?

re,
 wh


>  		if (!found) {
>  			free(dirpath);
>  			dirpath = NULL;
>  		}
> -		while (num--)
> -			free(list[num]);
> +		while (num > 0)
> +			free(list[--num]);
>  		free(list);
>  	}
>  


More information about the xorg-devel mailing list