Even more correctly free config file names

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 3d635fe84d

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@oracle.com>
Reviewed-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
This commit is contained in:
Alan Coopersmith 2011-12-10 10:01:18 -08:00
parent 33d6e6743d
commit b2bc38e4a5

View File

@ -2300,15 +2300,16 @@ checkInput(serverLayoutPtr layout, Bool implicit_layout) {
ConfigStatus
xf86HandleConfigFile(Bool autoconfig)
{
char *filename, *dirname, *sysdirname;
const char *filesearch, *dirsearch;
MessageType filefrom = X_DEFAULT;
MessageType dirfrom = X_DEFAULT;
char *scanptr;
Bool singlecard = 0;
Bool implicit_layout = FALSE;
if (!autoconfig) {
char *filename, *dirname, *sysdirname;
const char *filesearch, *dirsearch;
MessageType filefrom = X_DEFAULT;
MessageType dirfrom = X_DEFAULT;
if (getuid() == 0) {
filesearch = ROOT_CONFIGPATH;
dirsearch = ROOT_CONFIGDIRPATH;
@ -2350,11 +2351,11 @@ xf86HandleConfigFile(Bool autoconfig)
sysdirname);
if (!filename && !dirname && !sysdirname)
return CONFIG_NOFILE;
}
free(filename);
free(dirname);
free(sysdirname);
free(filename);
free(dirname);
free(sysdirname);
}
if ((xf86configptr = xf86readConfigFile ()) == NULL) {
xf86Msg(X_ERROR, "Problem parsing the config file\n");