[X2Go-Commits] [nx-libs] 96/219: Screen.c: fix two memleaks

git-admin at x2go.org git-admin at x2go.org
Sat Sep 28 12:10:29 CEST 2019


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch 3.6.x
in repository nx-libs.

commit 213e63eed7f808633dc865af94a9ea4ee703f228
Author: Ulrich Sibiller <uli42 at gmx.de>
Date:   Thu Jun 20 01:21:44 2019 +0200

    Screen.c: fix two memleaks
    
    While at it create and use the freeDepths() helper function.
---
 nx-X11/programs/Xserver/hw/nxagent/Screen.c | 37 ++++++++++++++---------------
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/nx-X11/programs/Xserver/hw/nxagent/Screen.c b/nx-X11/programs/Xserver/hw/nxagent/Screen.c
index 147a3108d..67151733f 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Screen.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Screen.c
@@ -844,6 +844,19 @@ static int nxagentColorOffset(unsigned long mask)
   return count;
 }
 
+void freeDepths(DepthPtr depths, int num)
+{
+  for (int i = 0; i < num; i++)
+  {
+    #ifdef DEBUG
+    fprintf(stderr, "%s: freeing depth [%d] index [%d] vids [%p]\n", __func__, depths[i].depth, i, (void*) depths[i].vids);
+    #endif
+    free(depths[i].vids);
+    depths[i].vids = NULL;
+  }
+  free(depths);
+}
+
 Bool nxagentOpenScreen(ScreenPtr pScreen,
                            int argc, char *argv[])
 {
@@ -1335,6 +1348,7 @@ Bool nxagentOpenScreen(ScreenPtr pScreen,
 
     if (!pFrameBufferBits)
     {
+      freeDepths(depths, numDepths);
       return FALSE;
     }
 
@@ -1356,6 +1370,7 @@ Bool nxagentOpenScreen(ScreenPtr pScreen,
     if (!fbScreenInit(pScreen, pFrameBufferBits, nxagentOption(RootWidth), nxagentOption(RootHeight),
           monitorResolution, monitorResolution, PixmapBytePad(nxagentOption(RootWidth), rootDepth), bitsPerPixel))
     {
+      freeDepths(depths, numDepths);
       return FALSE;
     }
 
@@ -1391,15 +1406,7 @@ Bool nxagentOpenScreen(ScreenPtr pScreen,
      * by fbScreenInit with our own.
      */
 
-    for (int i = 0; i < pScreen->numDepths; i++)
-    {
-      #ifdef DEBUG
-      fprintf(stderr, "%s: freeing depth [%d] index [%d] vids [%p]\n", __func__, pScreen->allowedDepths[i].depth, i, (void*) pScreen->allowedDepths[i].vids);
-      #endif
-      free(pScreen->allowedDepths[i].vids);
-    }
-
-    free(pScreen -> allowedDepths);
+    freeDepths(pScreen->allowedDepths, pScreen->numDepths);
     pScreen -> allowedDepths = depths;
     pScreen -> numDepths = numDepths;
     pScreen -> rootDepth = rootDepth;
@@ -2155,15 +2162,8 @@ Bool nxagentCloseScreen(ScreenPtr pScreen)
    * them again.
    */
 
-  for (int i = 0; i < pScreen->numDepths; i++)
-  {
-    #ifdef DEBUG
-    fprintf(stderr, "%s: freeing depth [%d] index [%d] vids [%p]\n", __func__, pScreen->allowedDepths[i].depth, i, (void*) pScreen->allowedDepths[i].vids);
-    #endif
-    free(pScreen->allowedDepths[i].vids);
-    pScreen->allowedDepths[i].vids = NULL;
-  }
-
+  freeDepths(pScreen->allowedDepths, pScreen->numDepths);
+  pScreen->allowedDepths = NULL;
   pScreen->numDepths = 0;
 
   /*
@@ -2172,7 +2172,6 @@ Bool nxagentCloseScreen(ScreenPtr pScreen)
 
   free(((PixmapPtr)pScreen -> devPrivate) -> devPrivate.ptr);
   free(pScreen->devPrivate);pScreen->devPrivate = NULL;
-  free(pScreen->allowedDepths); pScreen->allowedDepths = NULL;
   free(pScreen->visuals); pScreen->visuals = NULL;
 
   fbCloseScreen(pScreen);

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/nx-libs.git


More information about the x2go-commits mailing list