[PATCH] Even more correctly free config file names

Paulo Zanoni przanoni at gmail.com
Mon Dec 12 14:34:58 PST 2011


2011/12/10 Alan Coopersmith <alan.coopersmith at oracle.com>:
> If we didn't go into the if (!autoconfig) { } block, the filename,
> dirname, and sysdirname pointers were never initialized, but we
> freed them outside the block, leading to potential memory corruption.
>
> Move the frees inside the block where they're initialized to avoid this.
>
> To avoid similar problems, move the declarations of the variables that
> are only used in this block inside the block.
>
> Regression introduced by commit 3d635fe84d6de53e2f74203b10e89f7851fe3fc1
>
> Found by gcc warning:
> xf86Config.c: In function 'xf86HandleConfigFile':
> xf86Config.c:2303:11: warning: 'filename' may be used uninitialized in this function
> xf86Config.c:2303:22: warning: 'dirname' may be used uninitialized in this function
> xf86Config.c:2303:32: warning: 'sysdirname' may be used uninitialized in this function
>
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
Reviewed-by: Paulo Zanoni <paulo.r.zanoni at intel.com>

Another option would have been to set everything to NULL.

The funniest thing here was trying to find out why I didn't have this
warning on my machine. I put some stuff in CFLAGS, so I don't get
"-O2" in my compilation, so gcc can't detect the uninitialized usage.

Thanks,
Paulo

-- 
Paulo Zanoni


More information about the xorg-devel mailing list