[PATCH] Even more correctly free config file names
Alan Coopersmith
alan.coopersmith at oracle.com
Sat Dec 10 10:17:19 PST 2011
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>
---
hw/xfree86/common/xf86Config.c | 17 +++++++++--------
1 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index fef4bf1..94d2b15 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");
--
1.7.3.2
More information about the xorg-devel
mailing list