xserver: Branch 'server-1.10-branch' - 4 commits

Jeremy Huddleston jeremyhu at kemper.freedesktop.org
Fri May 13 23:43:58 PDT 2011


 dbe/dbe.c                             |   25 +++++++++++--------------
 hw/xfree86/Makefile.am                |    2 +-
 hw/xquartz/mach-startup/bundle-main.c |   24 +++++++++++++++++++++---
 record/record.c                       |    2 +-
 4 files changed, 34 insertions(+), 19 deletions(-)

New commits:
commit 0a61aca1ed036b17cab48725eb6ab4d860c9aad8
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Tue Apr 19 19:02:54 2011 -0700

    Clean up memory better when GetVisualInfo fails in ProcDbeGetVisualInfo
    
    Use calloc to initialize pScrVisInfo array so we don't have to check
    which ones were already initialized when freeing them all.
    
    On failure, set rc if necessary, and jump to code at end that already
    frees all the necessary allocations and return rc.
    
    Fixes parfait reported error:
    Error: Memory leak (CWE 401)
       Memory leak of pointer 'pScrVisInfo' allocated with malloc((count * 16))
            at line 724 of dbe/dbe.c in function 'ProcDbeGetVisualInfo'.
              'pScrVisInfo' allocated at line 693 with malloc((count * 16)).
              pScrVisInfo leaks when rc != 0 at line 710
                  and j >= i at line 716.
    
    [ This bug was found by the Parfait 0.3.7 bug checking tool.
      For more information see http://labs.oracle.com/projects/parfait/ ]
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    (cherry picked from commit 043c1758652259fd12b88ae37720fe6e93eda76b)

diff --git a/dbe/dbe.c b/dbe/dbe.c
index 77b616b..51bbdc6 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -690,8 +690,7 @@ ProcDbeGetVisualInfo(ClientPtr client)
     }
 
     count = (stuff->n == 0) ? screenInfo.numScreens : stuff->n;
-    if (!(pScrVisInfo = (XdbeScreenVisualInfo *)malloc(count *
-                        sizeof(XdbeScreenVisualInfo))))
+    if (!(pScrVisInfo = calloc(count, sizeof(XdbeScreenVisualInfo))))
     {
         free(pDrawables);
 
@@ -707,21 +706,16 @@ ProcDbeGetVisualInfo(ClientPtr client)
         pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen);
 
 	rc = XaceHook(XACE_SCREEN_ACCESS, client, pScreen, DixGetAttrAccess);
-	if ((rc != Success) ||
-	    !(*pDbeScreenPriv->GetVisualInfo)(pScreen, &pScrVisInfo[i]))
+        if (rc != Success)
+            goto freeScrVisInfo;
+
+        if (!(*pDbeScreenPriv->GetVisualInfo)(pScreen, &pScrVisInfo[i]))
         {
             /* We failed to alloc pScrVisInfo[i].visinfo. */
+            rc = BadAlloc;
 
             /* Free visinfos that we allocated for previous screen infos.*/
-            for (j = 0; j < i; j++)
-            {
-                free(pScrVisInfo[j].visinfo);
-            }
-
-            /* Free pDrawables if we needed to allocate it above. */
-            free(pDrawables);
-
-            return (rc == Success) ? BadAlloc : rc;
+            goto freeScrVisInfo;
         }
 
         /* Account for n, number of xDbeVisInfo items in list. */
@@ -790,6 +784,9 @@ ProcDbeGetVisualInfo(ClientPtr client)
         }
     }
 
+    rc = Success;
+
+  freeScrVisInfo:
     /* Clean up memory. */
     for (i = 0; i < count; i++)
     {
@@ -799,7 +796,7 @@ ProcDbeGetVisualInfo(ClientPtr client)
 
     free(pDrawables);
 
-    return Success;
+    return rc;
 
 } /* ProcDbeGetVisualInfo() */
 
commit 5be7451367901c13a697ecefcb634920cd156cb7
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Tue Apr 19 18:53:22 2011 -0700

    Only free pContext once when AddResource fails in ProcRecordCreateContext
    
    Since RecordDeleteContext frees its argument, don't fall through to free
    it again.
    
    Error: Double free (CWE 415)
       Double free of pointer 'malloc(1072)' defined by malloc
            at line 1964 of record/record.c in function 'ProcRecordCreateContext'.
              Previously freed at line 1960 with RecordDeleteContext.
              'malloc(1072)' was allocated at line 1926 with malloc.
    
    [ This bug was found by the Parfait 0.3.7 bug checking tool.
      For more information see http://labs.oracle.com/projects/parfait/ ]
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    (cherry picked from commit dadb0791ebfd05cd3bb82d4addf0fbc21aad6fbb)

diff --git a/record/record.c b/record/record.c
index facaebb..f466758 100644
--- a/record/record.c
+++ b/record/record.c
@@ -1956,7 +1956,7 @@ ProcRecordCreateContext(ClientPtr client)
     else
     {
 	RecordDeleteContext((pointer)pContext, pContext->id);
-	err = BadAlloc;
+	return BadAlloc;
     }
 bailout:
     free(pContext);
commit ee69c1aa7c1066b2019bf916230332c60a837ecb
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Fri Mar 11 15:43:14 2011 -0800

    Make xorg.conf.example rule compatible with Solaris make
    
    Solaris make won't substitute $< in explicit rules, only implicit ones
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Gaetan Nadon <memsize at videotron.ca>
    (cherry picked from commit 8d229c4cf9e5bde78373ef3dd32708817ac97152)

diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index c23b1fd..93995c6 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -114,7 +114,7 @@ CONF_SUBSTS =	-e 's|__filemansuffix__|$(FILE_MAN_SUFFIX)|g' \
 		-e 's|DEFAULTFONTPATH|$(COMPILEDDEFAULTFONTPATH)|g'
 
 xorg.conf.example: xorgconf.cpp
-	$(AM_V_GEN)$(SED) $(CONF_SUBSTS) < $< > $@
+	$(AM_V_GEN)$(SED) $(CONF_SUBSTS) < $(srcdir)/xorgconf.cpp > $@
 
 relink:
 	$(AM_V_at)rm -f Xorg && $(MAKE) Xorg
commit 189d44e7d216cc7b13f3e5a22689f2841a08b421
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Tue May 10 23:42:46 2011 -0700

    XQuartz: Don't call into CoreFoundation after fork() and before exec()
    
    After fork()ing, we should just limit ourselves to setting up
    the environment, file descriptors, and exec()ing.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    (cherry picked from commit  c89a6f824eaf647d2b182f79fbd78f5bd1c3a27f)

diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index d55d1ed..1ddaa2c 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -36,6 +36,7 @@
 #endif
 
 #include <X11/Xlib.h>
+#include <assert.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <string.h>
@@ -94,6 +95,10 @@ int server_main(int argc, char **argv, char **envp);
 static int execute(const char *command);
 static char *command_from_prefs(const char *key, const char *default_value);
 
+static char *pref_app_to_run;
+static char *pref_login_shell;
+static char *pref_startx_script;
+
 /*** Pthread Magics ***/
 static pthread_t create_thread(void *(*func)(void *), void *arg) {
     pthread_attr_t attr;
@@ -415,7 +420,7 @@ static int startup_trigger(int argc, char **argv, char **envp) {
             /* Could open the display, start the launcher */
             XCloseDisplay(display);
 
-            return execute(command_from_prefs("app_to_run", DEFAULT_CLIENT));
+            return execute(pref_app_to_run);
         }
     }
 
@@ -426,7 +431,7 @@ static int startup_trigger(int argc, char **argv, char **envp) {
     } else {
         fprintf(stderr, "X11.app: Could not connect to server (DISPLAY is not set).  Starting X server.\n");
     }
-    return execute(command_from_prefs("startx_script", DEFAULT_STARTX));
+    return execute(pref_startx_script);
 }
 
 /** Setup the environment we want our child processes to inherit */
@@ -563,6 +568,15 @@ int main(int argc, char **argv, char **envp) {
         pid_t child1, child2;
         int status;
 
+        pref_app_to_run = command_from_prefs("app_to_run", DEFAULT_CLIENT);
+        assert(pref_app_to_run);
+
+        pref_login_shell = command_from_prefs("login_shell", DEFAULT_SHELL);
+        assert(pref_login_shell);
+
+        pref_startx_script = command_from_prefs("startx_script", DEFAULT_STARTX);
+        assert(pref_startx_script);
+
         /* Do the fork-twice trick to avoid having to reap zombies */
         child1 = fork();
         switch (child1) {
@@ -598,6 +612,10 @@ int main(int argc, char **argv, char **envp) {
             default:                                /* parent */
               waitpid(child1, &status, 0);
         }
+
+        free(pref_app_to_run);
+        free(pref_login_shell);
+        free(pref_startx_script);
     }
     
     /* Main event loop */
@@ -615,7 +633,7 @@ static int execute(const char *command) {
     const char *newargv[4];
     const char **p;
     
-    newargv[0] = command_from_prefs("login_shell", DEFAULT_SHELL);
+    newargv[0] = pref_login_shell;
     newargv[1] = "-c";
     newargv[2] = command;
     newargv[3] = NULL;


More information about the xorg-commit mailing list