summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2011-12-10 10:01:18 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2011-12-12 16:50:25 -0800
commitb2bc38e4a553c29f49a0284333b34b4d6c8a8c12 (patch)
treed11c7e7268576d5658cce1003986f19a602ff6d3
parent33d6e6743d86324c2078f156991b16ac4f2593fc (diff)
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 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@oracle.com> Reviewed-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
-rw-r--r--hw/xfree86/common/xf86Config.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index fef4bf1fe..94d2b1596 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -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");