Unverified Commit 6f80a06f authored by Mike Gabriel's avatar Mike Gabriel

Merge branch 'uli42-pr/safe_free' into 3.6.x

parents 8b15d574 f39b81d3
...@@ -195,7 +195,7 @@ int ddxProcessArgument(int argc, char *argv[], int i) ...@@ -195,7 +195,7 @@ int ddxProcessArgument(int argc, char *argv[], int i)
{ {
char *basec = strdup(argv[0]); char *basec = strdup(argv[0]);
nxagentProgName = strdup(basename(basec)); nxagentProgName = strdup(basename(basec));
free(basec); SAFE_free(basec);
/* /*
* Check if we are running as X2Go Agent * Check if we are running as X2Go Agent
...@@ -270,7 +270,7 @@ int ddxProcessArgument(int argc, char *argv[], int i) ...@@ -270,7 +270,7 @@ int ddxProcessArgument(int argc, char *argv[], int i)
{ {
nxagentParseOptionString(envOptions); nxagentParseOptionString(envOptions);
free(envOptions); SAFE_free(envOptions);
} }
for (j = 0; j < argc; j++) for (j = 0; j < argc; j++)
...@@ -378,8 +378,7 @@ int ddxProcessArgument(int argc, char *argv[], int i) ...@@ -378,8 +378,7 @@ int ddxProcessArgument(int argc, char *argv[], int i)
{ {
if (++i < argc) if (++i < argc)
{ {
free(nxagentOptionsFilenameOrString); SAFE_free(nxagentOptionsFilenameOrString);
nxagentOptionsFilenameOrString = NULL;
if (-1 == asprintf(&nxagentOptionsFilenameOrString, "%s", argv[i])) if (-1 == asprintf(&nxagentOptionsFilenameOrString, "%s", argv[i]))
{ {
...@@ -716,8 +715,7 @@ int ddxProcessArgument(int argc, char *argv[], int i) ...@@ -716,8 +715,7 @@ int ddxProcessArgument(int argc, char *argv[], int i)
{ {
if (++i < argc) if (++i < argc)
{ {
free(nxagentKeyboard); SAFE_free(nxagentKeyboard);
nxagentKeyboard = NULL;
nxagentKeyboard = strdup(argv[i]); nxagentKeyboard = strdup(argv[i]);
if (nxagentKeyboard == NULL) if (nxagentKeyboard == NULL)
...@@ -1574,7 +1572,7 @@ static void nxagentParseSingleOption(char *name, char *value) ...@@ -1574,7 +1572,7 @@ static void nxagentParseSingleOption(char *name, char *value)
ddxProcessArgument(argc, argv, 0); ddxProcessArgument(argc, argv, 0);
free(argv[0]); SAFE_free(argv[0]);
} }
static void nxagentParseOptionString(char *string) static void nxagentParseOptionString(char *string)
...@@ -1761,7 +1759,7 @@ void nxagentProcessOptionsFile(char * filename) ...@@ -1761,7 +1759,7 @@ void nxagentProcessOptionsFile(char * filename)
nxagentProcessOptionsFileExit: nxagentProcessOptionsFileExit:
free(data); SAFE_free(data);
if (file) if (file)
{ {
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "Screen.h" #include "Screen.h"
#include "Options.h" #include "Options.h"
#include "Agent.h" #include "Agent.h"
#include "Utils.h"
/* /*
* Set here the required log level. * Set here the required log level.
...@@ -53,11 +54,6 @@ ...@@ -53,11 +54,6 @@
#undef TEST #undef TEST
#undef DEBUG #undef DEBUG
#ifdef DEBUG
/* for validateString() */
#include "Utils.h"
#endif
/* /*
* These values should be moved in * These values should be moved in
* the option repository. * the option repository.
...@@ -482,8 +478,8 @@ static int nxagentInitAtomMap(char **atomNameList, int count, Atom *atomsRet) ...@@ -482,8 +478,8 @@ static int nxagentInitAtomMap(char **atomNameList, int count, Atom *atomsRet)
fprintf(stderr, "nxagentInitAtomMap: WARNING! XInternAtoms request failed.\n"); fprintf(stderr, "nxagentInitAtomMap: WARNING! XInternAtoms request failed.\n");
#endif #endif
free(atom_list); SAFE_free(atom_list);
free(name_list); SAFE_free(name_list);
return 0; return 0;
} }
...@@ -523,8 +519,8 @@ static int nxagentInitAtomMap(char **atomNameList, int count, Atom *atomsRet) ...@@ -523,8 +519,8 @@ static int nxagentInitAtomMap(char **atomNameList, int count, Atom *atomsRet)
} }
} }
free(atom_list); SAFE_free(atom_list);
free(name_list); SAFE_free(name_list);
nxagentPrintAtomMapInfo("nxagentInitAtomMap: Exiting"); nxagentPrintAtomMapInfo("nxagentInitAtomMap: Exiting");
...@@ -794,7 +790,7 @@ Atom nxagentRemoteToLocalAtom(Atom remote) ...@@ -794,7 +790,7 @@ Atom nxagentRemoteToLocalAtom(Atom remote)
#ifdef TEST #ifdef TEST
fprintf(stderr, "%s: remote [%d (%s)] -> local [%d]\n", __func__, remote, string, local); fprintf(stderr, "%s: remote [%d (%s)] -> local [%d]\n", __func__, remote, string, local);
#endif #endif
XFree(string); SAFE_XFree(string);
return local; return local;
} }
......
...@@ -1783,8 +1783,7 @@ int nxagentInitClipboard(WindowPtr pWin) ...@@ -1783,8 +1783,7 @@ int nxagentInitClipboard(WindowPtr pWin)
fprintf(stderr, "%s: Got called.\n", __func__); fprintf(stderr, "%s: Got called.\n", __func__);
#endif #endif
free(lastSelectionOwner); SAFE_free(lastSelectionOwner);
lastSelectionOwner = NULL;
lastSelectionOwner = (SelectionOwner *) malloc(nxagentMaxSelections * sizeof(SelectionOwner)); lastSelectionOwner = (SelectionOwner *) malloc(nxagentMaxSelections * sizeof(SelectionOwner));
......
...@@ -54,6 +54,7 @@ is" without express or implied warranty. ...@@ -54,6 +54,7 @@ is" without express or implied warranty.
#include "Visual.h" #include "Visual.h"
#include "Windows.h" #include "Windows.h"
#include "Args.h" #include "Args.h"
#include "Utils.h"
#define PANIC #define PANIC
#define WARNING #define WARNING
...@@ -120,7 +121,7 @@ Bool nxagentCreateColormap(ColormapPtr pCmap) ...@@ -120,7 +121,7 @@ Bool nxagentCreateColormap(ColormapPtr pCmap)
pCmap->red[i].co.local.green = colors[i].red; pCmap->red[i].co.local.green = colors[i].red;
pCmap->red[i].co.local.blue = colors[i].red; pCmap->red[i].co.local.blue = colors[i].red;
} }
free(colors); SAFE_free(colors);
break; break;
case StaticColor: /* read only */ case StaticColor: /* read only */
...@@ -133,7 +134,7 @@ Bool nxagentCreateColormap(ColormapPtr pCmap) ...@@ -133,7 +134,7 @@ Bool nxagentCreateColormap(ColormapPtr pCmap)
pCmap->red[i].co.local.green = colors[i].green; pCmap->red[i].co.local.green = colors[i].green;
pCmap->red[i].co.local.blue = colors[i].blue; pCmap->red[i].co.local.blue = colors[i].blue;
} }
free(colors); SAFE_free(colors);
break; break;
case TrueColor: /* read only */ case TrueColor: /* read only */
...@@ -157,7 +158,7 @@ Bool nxagentCreateColormap(ColormapPtr pCmap) ...@@ -157,7 +158,7 @@ Bool nxagentCreateColormap(ColormapPtr pCmap)
pCmap->green[i].co.local.green = colors[i].green; pCmap->green[i].co.local.green = colors[i].green;
pCmap->blue[i].co.local.blue = colors[i].blue; pCmap->blue[i].co.local.blue = colors[i].blue;
} }
free(colors); SAFE_free(colors);
break; break;
case GrayScale: /* read and write */ case GrayScale: /* read and write */
...@@ -176,7 +177,7 @@ Bool nxagentCreateColormap(ColormapPtr pCmap) ...@@ -176,7 +177,7 @@ Bool nxagentCreateColormap(ColormapPtr pCmap)
void nxagentDestroyColormap(ColormapPtr pCmap) void nxagentDestroyColormap(ColormapPtr pCmap)
{ {
XFreeColormap(nxagentDisplay, nxagentColormap(pCmap)); XFreeColormap(nxagentDisplay, nxagentColormap(pCmap));
free(pCmap->devPriv); SAFE_free(pCmap->devPriv);
} }
#define SEARCH_PREDICATE \ #define SEARCH_PREDICATE \
...@@ -254,10 +255,10 @@ void nxagentSetInstalledColormapWindows(ScreenPtr pScreen) ...@@ -254,10 +255,10 @@ void nxagentSetInstalledColormapWindows(ScreenPtr pScreen)
numWindows = 0; numWindows = 0;
} }
free(icws.cmapIDs); SAFE_free(icws.cmapIDs);
if (!nxagentSameInstalledColormapWindows(icws.windows, icws.numWindows)) { if (!nxagentSameInstalledColormapWindows(icws.windows, icws.numWindows)) {
free(nxagentOldInstalledColormapWindows); SAFE_free(nxagentOldInstalledColormapWindows);
#ifdef _XSERVER64 #ifdef _XSERVER64
{ {
...@@ -268,7 +269,7 @@ void nxagentSetInstalledColormapWindows(ScreenPtr pScreen) ...@@ -268,7 +269,7 @@ void nxagentSetInstalledColormapWindows(ScreenPtr pScreen)
windows[i] = icws.windows[i]; windows[i] = icws.windows[i];
XSetWMColormapWindows(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum], XSetWMColormapWindows(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum],
windows, numWindows); windows, numWindows);
free(windows); SAFE_free(windows);
} }
#else #else
XSetWMColormapWindows(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum], XSetWMColormapWindows(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum],
...@@ -317,12 +318,12 @@ void nxagentSetInstalledColormapWindows(ScreenPtr pScreen) ...@@ -317,12 +318,12 @@ void nxagentSetInstalledColormapWindows(ScreenPtr pScreen)
#endif /* DUMB_WINDOW_MANAGERS */ #endif /* DUMB_WINDOW_MANAGERS */
} }
else else
free(icws.windows); SAFE_free(icws.windows);
} }
void nxagentSetScreenSaverColormapWindow(ScreenPtr pScreen) void nxagentSetScreenSaverColormapWindow(ScreenPtr pScreen)
{ {
free(nxagentOldInstalledColormapWindows); SAFE_free(nxagentOldInstalledColormapWindows);
#ifdef _XSERVER64 #ifdef _XSERVER64
{ {
...@@ -454,7 +455,7 @@ void nxagentStoreColors(ColormapPtr pCmap, int nColors, xColorItem *pColors) ...@@ -454,7 +455,7 @@ void nxagentStoreColors(ColormapPtr pCmap, int nColors, xColorItem *pColors)
pColors64[i].flags = pColors[i].flags; pColors64[i].flags = pColors[i].flags;
} }
XStoreColors(nxagentDisplay, nxagentColormap(pCmap), pColors64, nColors); XStoreColors(nxagentDisplay, nxagentColormap(pCmap), pColors64, nColors);
free(pColors64); SAFE_free(pColors64);
} }
#else #else
XStoreColors(nxagentDisplay, nxagentColormap(pCmap), XStoreColors(nxagentDisplay, nxagentColormap(pCmap),
......
...@@ -61,6 +61,7 @@ is" without express or implied warranty. ...@@ -61,6 +61,7 @@ is" without express or implied warranty.
#include "Events.h" #include "Events.h"
#include "Render.h" #include "Render.h"
#include "Client.h" #include "Client.h"
#include "Utils.h"
#include "windowstr.h" #include "windowstr.h"
#include "resource.h" #include "resource.h"
...@@ -211,7 +212,7 @@ Bool nxagentRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor) ...@@ -211,7 +212,7 @@ Bool nxagentRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
XPutImage(nxagentDisplay, source, nxagentBitmapGC, image, XPutImage(nxagentDisplay, source, nxagentBitmapGC, image,
0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height); 0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height);
XFree(image); SAFE_XFree(image);
image = XCreateImage(nxagentDisplay, image = XCreateImage(nxagentDisplay,
nxagentDefaultVisual(pScreen), nxagentDefaultVisual(pScreen),
...@@ -229,7 +230,7 @@ Bool nxagentRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor) ...@@ -229,7 +230,7 @@ Bool nxagentRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
XPutImage(nxagentDisplay, mask, nxagentBitmapGC, image, XPutImage(nxagentDisplay, mask, nxagentBitmapGC, image,
0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height); 0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height);
XFree(image); SAFE_XFree(image);
fg_color.red = pCursor->foreRed; fg_color.red = pCursor->foreRed;
fg_color.green = pCursor->foreGreen; fg_color.green = pCursor->foreGreen;
...@@ -264,14 +265,12 @@ Bool nxagentUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor) ...@@ -264,14 +265,12 @@ Bool nxagentUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
if (nxagentCursorUsesRender(pCursor, pScreen)) if (nxagentCursorUsesRender(pCursor, pScreen))
{ {
PicturePtr pPicture = nxagentCursorPicture(pCursor, pScreen); PicturePtr pPicture = nxagentCursorPicture(pCursor, pScreen);
FreePicture(pPicture, pPicture -> id); FreePicture(pPicture, pPicture -> id);
} }
if (nxagentCursor(pCursor, pScreen) != None) if (nxagentCursor(pCursor, pScreen) != None)
{ {
XFreeCursor(nxagentDisplay, nxagentCursor(pCursor, pScreen)); XFreeCursor(nxagentDisplay, nxagentCursor(pCursor, pScreen));
nxagentCursor(pCursor, pScreen) = None; nxagentCursor(pCursor, pScreen) = None;
} }
......
...@@ -71,6 +71,7 @@ is" without express or implied warranty. ...@@ -71,6 +71,7 @@ is" without express or implied warranty.
#include "Init.h" #include "Init.h"
#include "Args.h" #include "Args.h"
#include "Image.h" #include "Image.h"
#include "Utils.h"
#define Pixmap XlibPixmap #define Pixmap XlibPixmap
#include "Icons.h" #include "Icons.h"
...@@ -1534,7 +1535,7 @@ void nxagentInitVisuals(void) ...@@ -1534,7 +1535,7 @@ void nxagentInitVisuals(void)
nxagentNumVisuals * sizeof(XVisualInfo)); nxagentNumVisuals * sizeof(XVisualInfo));
} }
XFree(viList); SAFE_XFree(viList);
if (nxagentNumVisuals == 0 || nxagentVisuals == NULL) if (nxagentNumVisuals == 0 || nxagentVisuals == NULL)
{ {
...@@ -1756,20 +1757,11 @@ void nxagentCloseDisplay(void) ...@@ -1756,20 +1757,11 @@ void nxagentCloseDisplay(void)
* traffic * traffic
*/ */
free(nxagentDefaultColormaps); SAFE_free(nxagentDefaultColormaps);
nxagentDefaultColormaps = NULL; SAFE_free(nxagentDepths);
SAFE_XFree(nxagentVisuals);
XFree(nxagentVisuals); SAFE_XFree(nxagentPixmapFormats);
nxagentVisuals = NULL; SAFE_XFree(nxagentRemotePixmapFormats);
free(nxagentDepths);
nxagentDepths = NULL;
XFree(nxagentPixmapFormats);
nxagentPixmapFormats = NULL;
XFree(nxagentRemotePixmapFormats);
nxagentRemotePixmapFormats = NULL;
nxagentFreeFontCache(); nxagentFreeFontCache();
/* /*
...@@ -2008,11 +2000,7 @@ void nxagentBackupDisplayInfo(void) ...@@ -2008,11 +2000,7 @@ void nxagentBackupDisplayInfo(void)
nxagentNumDefaultColormapsRecBackup = nxagentNumDefaultColormaps; nxagentNumDefaultColormapsRecBackup = nxagentNumDefaultColormaps;
nxagentVisualsRecBackup = nxagentVisuals; nxagentVisualsRecBackup = nxagentVisuals;
nxagentNumVisualsRecBackup = nxagentNumVisuals; nxagentNumVisualsRecBackup = nxagentNumVisuals;
if (nxagentVisualHasBeenIgnored) SAFE_free(nxagentVisualHasBeenIgnored);
{
free(nxagentVisualHasBeenIgnored);
nxagentVisualHasBeenIgnored = NULL;
}
nxagentVisualHasBeenIgnored = malloc(nxagentNumVisuals * sizeof(Bool)); nxagentVisualHasBeenIgnored = malloc(nxagentNumVisuals * sizeof(Bool));
nxagentDefaultDepthRecBackup = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay)); nxagentDefaultDepthRecBackup = DefaultDepth(nxagentDisplay, DefaultScreen(nxagentDisplay));
nxagentDisplayWidthRecBackup = DisplayWidth(nxagentDisplay, DefaultScreen(nxagentDisplay)); nxagentDisplayWidthRecBackup = DisplayWidth(nxagentDisplay, DefaultScreen(nxagentDisplay));
...@@ -2024,20 +2012,11 @@ void nxagentBackupDisplayInfo(void) ...@@ -2024,20 +2012,11 @@ void nxagentBackupDisplayInfo(void)
void nxagentCleanupBackupDisplayInfo(void) void nxagentCleanupBackupDisplayInfo(void)
{ {
free(nxagentDepthsRecBackup); SAFE_free(nxagentDepthsRecBackup);
nxagentNumDepthsRecBackup = 0; SAFE_free(nxagentVisualsRecBackup);
SAFE_free(nxagentVisualHasBeenIgnored);
nxagentNumDefaultColormapsRecBackup = 0; nxagentNumDefaultColormapsRecBackup = 0;
free(nxagentVisualsRecBackup);
nxagentNumVisualsRecBackup = 0;
if (nxagentVisualHasBeenIgnored)
{
free(nxagentVisualHasBeenIgnored);
nxagentVisualHasBeenIgnored = NULL;
}
nxagentDefaultDepthRecBackup = 0; nxagentDefaultDepthRecBackup = 0;
nxagentDisplayWidthRecBackup = 0; nxagentDisplayWidthRecBackup = 0;
nxagentDisplayHeightRecBackup = 0; nxagentDisplayHeightRecBackup = 0;
...@@ -2045,7 +2024,6 @@ void nxagentCleanupBackupDisplayInfo(void) ...@@ -2045,7 +2024,6 @@ void nxagentCleanupBackupDisplayInfo(void)
if (nxagentDisplayBackup) if (nxagentDisplayBackup)
{ {
XCloseDisplay(nxagentDisplayBackup); XCloseDisplay(nxagentDisplayBackup);
nxagentDisplayBackup = NULL; nxagentDisplayBackup = NULL;
} }
...@@ -2057,7 +2035,7 @@ void nxagentCleanupBackupDisplayInfo(void) ...@@ -2057,7 +2035,7 @@ void nxagentCleanupBackupDisplayInfo(void)
} }
else else
{ {
free(nxagentBitmapGCBackup); SAFE_free(nxagentBitmapGCBackup);
} }
nxagentBitmapGCBackup = NULL; nxagentBitmapGCBackup = NULL;
...@@ -2560,7 +2538,7 @@ FIXME: Should the visual be ignored in this case? ...@@ -2560,7 +2538,7 @@ FIXME: Should the visual be ignored in this case?
} }
} }
XFree(viList); SAFE_XFree(viList);
if (compatible) if (compatible)
{ {
...@@ -2576,7 +2554,7 @@ FIXME: Should the visual be ignored in this case? ...@@ -2576,7 +2554,7 @@ FIXME: Should the visual be ignored in this case?
fprintf(stderr, "nxagentInitAndCheckVisuals: New visuals don't match with old visuals.\n"); fprintf(stderr, "nxagentInitAndCheckVisuals: New visuals don't match with old visuals.\n");
#endif #endif
free(newVisuals); SAFE_free(newVisuals);
} }
return compatible; return compatible;
...@@ -2757,19 +2735,8 @@ Bool nxagentReconnectDisplay(void *p0) ...@@ -2757,19 +2735,8 @@ Bool nxagentReconnectDisplay(void *p0)
* will be reallocated in nxagentInitPixmapFormats(). * will be reallocated in nxagentInitPixmapFormats().
*/ */
if (nxagentPixmapFormats != NULL) SAFE_XFree(nxagentPixmapFormats);
{ SAFE_XFree(nxagentRemotePixmapFormats);
XFree(nxagentPixmapFormats);
nxagentPixmapFormats = NULL;
}
if (nxagentRemotePixmapFormats != NULL)
{
XFree(nxagentRemotePixmapFormats);
nxagentRemotePixmapFormats = NULL;
}
/* /*
* Check if all the required pixmap * Check if all the required pixmap
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "Pixels.h" #include "Pixels.h"
#include "Reconnect.h" #include "Reconnect.h"
#include "GCOps.h" #include "GCOps.h"
#include "Utils.h"
#include "compext/Compext.h" #include "compext/Compext.h"
...@@ -365,7 +366,7 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask ...@@ -365,7 +366,7 @@ int nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask
success = nxagentSynchronizeRegion(pDrawable, NullRegion, breakMask, owner); success = nxagentSynchronizeRegion(pDrawable, NullRegion, breakMask, owner);
nxagentSynchronizeDrawableDataEnd: nxagentSynchronizeDrawableDataEnd:
free(data); SAFE_free(data);
return success; return success;
} }
...@@ -861,7 +862,7 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned ...@@ -861,7 +862,7 @@ int nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned
#endif #endif
} }
free(cmpData); SAFE_free(cmpData);
} }
} }
else else
...@@ -1058,7 +1059,7 @@ nxagentSynchronizeRegionFree: ...@@ -1058,7 +1059,7 @@ nxagentSynchronizeRegionFree:
nxagentFreeRegion(pDrawable, clipRegion); nxagentFreeRegion(pDrawable, clipRegion);
} }
free(data); SAFE_free(data);
RegionUninit(&exposeRegion); RegionUninit(&exposeRegion);
...@@ -2158,7 +2159,7 @@ unsigned long nxagentGetColor(DrawablePtr pDrawable, int xPixel, int yPixel) ...@@ -2158,7 +2159,7 @@ unsigned long nxagentGetColor(DrawablePtr pDrawable, int xPixel, int yPixel)
fprintf(stderr, "nxagentGetColor: WARNING! Failed to create the XImage.\n"); fprintf(stderr, "nxagentGetColor: WARNING! Failed to create the XImage.\n");
#endif #endif
free(data); SAFE_free(data);
return -1; return -1;
} }
...@@ -2384,7 +2385,7 @@ void nxagentFillRemoteRegion(DrawablePtr pDrawable, RegionPtr pRegion) ...@@ -2384,7 +2385,7 @@ void nxagentFillRemoteRegion(DrawablePtr pDrawable, RegionPtr pRegion)
XFillRectangles(nxagentDisplay, nxagentDrawable(pDrawable), nxagentGC(pGC), XFillRectangles(nxagentDisplay, nxagentDrawable(pDrawable), nxagentGC(pGC),
pRects, nrects); pRects, nrects);
free(pRects); SAFE_free(pRects);
} }
} }
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "Error.h" #include "Error.h"
#include "Args.h" #include "Args.h"
#include "Utils.h"
/* /*
* Set here the required log level. * Set here the required log level.
...@@ -425,7 +426,7 @@ char *nxagentGetRootPath(void) ...@@ -425,7 +426,7 @@ char *nxagentGetRootPath(void)
"home directory '%s'.\n", homeEnv); "home directory '%s'.\n", homeEnv);
#endif #endif
free(homeEnv); SAFE_free(homeEnv);
return NULL; return NULL;
} }
...@@ -436,7 +437,7 @@ char *nxagentGetRootPath(void) ...@@ -436,7 +437,7 @@ char *nxagentGetRootPath(void)
snprintf(nxagentRootDir, DEFAULT_STRING_LENGTH, "%s/.nx", homeEnv); snprintf(nxagentRootDir, DEFAULT_STRING_LENGTH, "%s/.nx", homeEnv);
free(homeEnv); SAFE_free(homeEnv);
/* /*
* Create the NX root directory. * Create the NX root directory.
...@@ -534,14 +535,14 @@ char *nxagentGetSessionPath(void) ...@@ -534,14 +535,14 @@ char *nxagentGetSessionPath(void)
nxagentSessionDir); nxagentSessionDir);
#endif #endif
free(rootPath); SAFE_free(rootPath);
return NULL; return NULL;
} }
snprintf(nxagentSessionDir, DEFAULT_STRING_LENGTH, "%s/C-%s", rootPath, nxagentSessionId); snprintf(nxagentSessionDir, DEFAULT_STRING_LENGTH, "%s/C-%s", rootPath, nxagentSessionId);
free(rootPath); SAFE_free(rootPath);
if ((stat(nxagentSessionDir, &dirStat) == -1) && (errno == ENOENT)) if ((stat(nxagentSessionDir, &dirStat) == -1) && (errno == ENOENT))
{ {
...@@ -595,14 +596,14 @@ void nxagentGetClientsPath(void) ...@@ -595,14 +596,14 @@ void nxagentGetClientsPath(void)
fprintf(stderr, "nxagentGetClientsPath: PANIC! Invalid value for the NX clients Log File Path ''.\n"); fprintf(stderr, "nxagentGetClientsPath: PANIC! Invalid value for the NX clients Log File Path ''.\n");
#endif #endif
free(sessionPath); SAFE_free(sessionPath);
return; return;
} }
snprintf(nxagentClientsLogName, NXAGENTCLIENTSLOGNAMELENGTH, "%s/clients", sessionPath); snprintf(nxagentClientsLogName, NXAGENTCLIENTSLOGNAMELENGTH, "%s/clients", sessionPath);
free(sessionPath); SAFE_free(sessionPath);
} }
return; return;
......
...@@ -328,7 +328,7 @@ void nxagentRemoteWindowID(Window window, Bool newline) ...@@ -328,7 +328,7 @@ void nxagentRemoteWindowID(Window window, Bool newline)
else if (winName) else if (winName)
{ {
fprintf(stderr, " \"%s\" ", winName); fprintf(stderr, " \"%s\" ", winName);
XFree(winName); SAFE_XFree(winName);
} }
#else #else
...@@ -476,10 +476,7 @@ void nxagentRemoteWindowsTree(Window window, int level) ...@@ -476,10 +476,7 @@ void nxagentRemoteWindowsTree(Window window, int level)
nxagentRemoteWindowsTree(childList[i], level + 1); nxagentRemoteWindowsTree(childList[i], level + 1);
} }
if (childList) SAFE_XFree((char *) childList);
{
XFree((char *) childList);
}
} }
#endif #endif
...@@ -3133,10 +3130,7 @@ int nxagentCheckWindowConfiguration(XConfigureEvent* X) ...@@ -3133,10 +3130,7 @@ int nxagentCheckWindowConfiguration(XConfigureEvent* X)
#endif #endif
} }
if (children_return) SAFE_XFree(children_return);
{
XFree(children_return);
}
#if 0 #if 0
fprintf(stderr, "nxagentCheckWindowConfiguration: Trees match: %s\n", fprintf(stderr, "nxagentCheckWindowConfiguration: Trees match: %s\n",
...@@ -3514,11 +3508,7 @@ int nxagentHandleReparentNotify(XEvent* X) ...@@ -3514,11 +3508,7 @@ int nxagentHandleReparentNotify(XEvent* X)
result = XQueryTree(nxagentDisplay, w, &root_return, result = XQueryTree(nxagentDisplay, w, &root_return,
&parent_return, &children_return, &nchildren_return); &parent_return, &children_return, &nchildren_return);
if (children_return) SAFE_XFree(children_return);
{
XFree(children_return);
children_return = NULL;
}
if (!result) if (!result)
{ {
...@@ -3556,11 +3546,7 @@ int nxagentHandleReparentNotify(XEvent* X) ...@@ -3556,11 +3546,7 @@ int nxagentHandleReparentNotify(XEvent* X)
#endif #endif
} }
if (children_return) SAFE_XFree(children_return);
{
XFree(children_return);
children_return = NULL;
}
} }
else else
{ {
...@@ -3624,11 +3610,7 @@ int nxagentHandleReparentNotify(XEvent* X) ...@@ -3624,11 +3610,7 @@ int nxagentHandleReparentNotify(XEvent* X)
result = XQueryTree(nxagentDisplay, w, &rootReturn, &parentReturn, result = XQueryTree(nxagentDisplay, w, &rootReturn, &parentReturn,
&childrenReturn, &nchildrenReturn); &childrenReturn, &nchildrenReturn);
if (childrenReturn) SAFE_XFree(childrenReturn);
{
XFree(childrenReturn);
childrenReturn = NULL;
}
if (parentReturn == rootReturn || parentReturn == 0 || result == 0) if (parentReturn == rootReturn || parentReturn == 0 || result == 0)
{ {
...@@ -4025,10 +4007,7 @@ void nxagentHandleCollectPropertyEvent(XEvent *X) ...@@ -4025,10 +4007,7 @@ void nxagentHandleCollectPropertyEvent(XEvent *X)
#endif #endif
} }
if (pszReturnData != NULL) SAFE_XFree(pszReturnData);
{
XFree(pszReturnData);
}
return; return;
} }
......
...@@ -188,11 +188,11 @@ void nxagentFreeFontCache(void) ...@@ -188,11 +188,11 @@ void nxagentFreeFontCache(void)
nxagentFreeFont(CACHE_FSTRUCT(i)); nxagentFreeFont(CACHE_FSTRUCT(i));
} }
free(CACHE_NAME(i)); SAFE_free(CACHE_NAME(i));
free(CACHE_ENTRY(i)); SAFE_free(CACHE_ENTRY(i));
} }
free(CACHE_ENTRY_PTR); SAFE_free(CACHE_ENTRY_PTR);
CACHE_ENTRY_PTR = NULL; CACHE_ENTRY_PTR = NULL;
CACHE_INDEX = 0; CACHE_INDEX = 0;
CACHE_SIZE = 0; CACHE_SIZE = 0;
...@@ -324,8 +324,7 @@ void nxagentListRemoteAddName(const char *name, int status) ...@@ -324,8 +324,7 @@ void nxagentListRemoteAddName(const char *name, int status)
if (nxagentRemoteFontList.list[pos]->name == NULL) if (nxagentRemoteFontList.list[pos]->name == NULL)
{ {
fprintf(stderr, "Font: remote list name memory allocation failed!.\n"); fprintf(stderr, "Font: remote list name memory allocation failed!.\n");
free(nxagentRemoteFontList.list[pos]); SAFE_free(nxagentRemoteFontList.list[pos]);
nxagentRemoteFontList.list[pos] = NULL;
return; return;
} }
} }
...@@ -351,18 +350,14 @@ static void nxagentFreeRemoteFontList(nxagentFontList *listRec) ...@@ -351,18 +350,14 @@ static void nxagentFreeRemoteFontList(nxagentFontList *listRec)
{ {
if (listRec -> list[l]) if (listRec -> list[l])
{ {
free(listRec -> list[l] -> name); SAFE_free(listRec -> list[l] -> name);
listRec -> list[l] -> name = NULL; SAFE_free(listRec -> list[l]);
free(listRec -> list[l]);
listRec -> list[l] = NULL;
} }
} }
listRec -> length = listRec -> listSize = 0; listRec -> length = listRec -> listSize = 0;
free(listRec -> list); SAFE_free(listRec -> list);
listRec -> list = NULL;
return; return;
} }
...@@ -434,7 +429,7 @@ Bool nxagentFontLookUp(const char *name) ...@@ -434,7 +429,7 @@ Bool nxagentFontLookUp(const char *name)
{ {
result = nxagentFontFind(scalable, &i); result = nxagentFontFind(scalable, &i);
free(scalable); SAFE_free(scalable);
} }
} }
...@@ -448,7 +443,7 @@ Bool nxagentFontLookUp(const char *name) ...@@ -448,7 +443,7 @@ Bool nxagentFontLookUp(const char *name)
{ {
result = nxagentFontFind(scalable, &i); result = nxagentFontFind(scalable, &i);
free(scalable); SAFE_free(scalable);
} }
} }
...@@ -813,7 +808,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP ...@@ -813,7 +808,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP
for (j = 0; j < numSearchFields; j++) for (j = 0; j < numSearchFields; j++)
{ {
free(searchFields[j]); SAFE_free(searchFields[j]);
} }
} }
} }
...@@ -830,7 +825,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP ...@@ -830,7 +825,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP
for (j = 0; j < numFontFields; j++) for (j = 0; j < numFontFields; j++)
{ {
free(fontNameFields[j]); SAFE_free(fontNameFields[j]);
} }
return fontStruct; return fontStruct;
...@@ -890,10 +885,8 @@ static void nxagentCollectFailedFont(FontPtr fpt, XID id) ...@@ -890,10 +885,8 @@ static void nxagentCollectFailedFont(FontPtr fpt, XID id)
if (nxagentFailedToReconnectFonts.font == NULL || nxagentFailedToReconnectFonts.id == NULL) if (nxagentFailedToReconnectFonts.font == NULL || nxagentFailedToReconnectFonts.id == NULL)
{ {
free(nxagentFailedToReconnectFonts.font); SAFE_free(nxagentFailedToReconnectFonts.font);
nxagentFailedToReconnectFonts.font = NULL; SAFE_free(nxagentFailedToReconnectFonts.id);
free(nxagentFailedToReconnectFonts.id);
nxagentFailedToReconnectFonts.id = NULL;
FatalError("Font: font not reconnected memory allocation failed!.\n"); FatalError("Font: font not reconnected memory allocation failed!.\n");
} }
...@@ -1050,7 +1043,7 @@ static void nxagentCleanCacheAfterReconnect(void) ...@@ -1050,7 +1043,7 @@ static void nxagentCleanCacheAfterReconnect(void)
{ {
if(CACHE_FSTRUCT(i) == NULL) if(CACHE_FSTRUCT(i) == NULL)
{ {
XFree(CACHE_NAME(i)); SAFE_XFree(CACHE_NAME(i));
real_size--; real_size--;
} }
} }
...@@ -1223,11 +1216,8 @@ static void nxagentFailedFontReconnect(FontPtr pFont, XID param1, void * param2) ...@@ -1223,11 +1216,8 @@ static void nxagentFailedFontReconnect(FontPtr pFont, XID param1, void * param2)
static void nxagentFreeFailedToReconnectFonts(void) static void nxagentFreeFailedToReconnectFonts(void)
{ {
free(nxagentFailedToReconnectFonts.font); SAFE_free(nxagentFailedToReconnectFonts.font);
nxagentFailedToReconnectFonts.font = NULL; SAFE_free(nxagentFailedToReconnectFonts.id);
free(nxagentFailedToReconnectFonts.id);
nxagentFailedToReconnectFonts.id = NULL;
nxagentFailedToReconnectFonts.size = 0; nxagentFailedToReconnectFonts.size = 0;
nxagentFailedToReconnectFonts.index = 0; nxagentFailedToReconnectFonts.index = 0;
...@@ -1321,7 +1311,7 @@ Bool nxagentReconnectFailedFonts(void *p0) ...@@ -1321,7 +1311,7 @@ Bool nxagentReconnectFailedFonts(void *p0)
nxagentListRemoteFonts("*", nxagentMaxFontNames); nxagentListRemoteFonts("*", nxagentMaxFontNames);
XFreeFontPath(fontPaths); XFreeFontPath(fontPaths);
free(newFontPaths); SAFE_free(newFontPaths);
return False; return False;
} }
...@@ -1332,7 +1322,7 @@ Bool nxagentReconnectFailedFonts(void *p0) ...@@ -1332,7 +1322,7 @@ Bool nxagentReconnectFailedFonts(void *p0)
XSetFontPath(nxagentDisplay, fontPaths, nPaths); XSetFontPath(nxagentDisplay, fontPaths, nPaths);
XFreeFontPath(fontPaths); XFreeFontPath(fontPaths);
free(newFontPaths); SAFE_free(newFontPaths);
nxagentCleanCacheAfterReconnect(); nxagentCleanCacheAfterReconnect();
...@@ -1442,7 +1432,7 @@ void nxagentVerifySingleFontPath(char **dest, const char *fontDir) ...@@ -1442,7 +1432,7 @@ void nxagentVerifySingleFontPath(char **dest, const char *fontDir)
if (rc == -1) if (rc == -1)
return; return;
free(*dest); SAFE_free(*dest);
*dest = tmppath; *dest = tmppath;
tmppath = NULL; tmppath = NULL;
} }
...@@ -1554,7 +1544,7 @@ XFontStruct* nxagentLoadQueryFont(register Display *dpy, char *name, FontPtr pFo ...@@ -1554,7 +1544,7 @@ XFontStruct* nxagentLoadQueryFont(register Display *dpy, char *name, FontPtr pFo
fprintf(stderr, "nxagentLoadQueryFont: WARNING! Font not found '%s'.\n", name); fprintf(stderr, "nxagentLoadQueryFont: WARNING! Font not found '%s'.\n", name);
#endif #endif
free(fs); SAFE_free(fs);
return (XFontStruct *) NULL; return (XFontStruct *) NULL;
} }
...@@ -1588,7 +1578,7 @@ XFontStruct* nxagentLoadQueryFont(register Display *dpy, char *name, FontPtr pFo ...@@ -1588,7 +1578,7 @@ XFontStruct* nxagentLoadQueryFont(register Display *dpy, char *name, FontPtr pFo
fprintf(stderr, "nxagentLoadQueryFont: WARNING! Failed allocation of XFontProp."); fprintf(stderr, "nxagentLoadQueryFont: WARNING! Failed allocation of XFontProp.");
#endif #endif
free((char *) fs); SAFE_free(fs);
return (XFontStruct *) NULL; return (XFontStruct *) NULL;
} }
...@@ -1622,18 +1612,17 @@ XFontStruct* nxagentLoadQueryFont(register Display *dpy, char *name, FontPtr pFo ...@@ -1622,18 +1612,17 @@ XFontStruct* nxagentLoadQueryFont(register Display *dpy, char *name, FontPtr pFo
int nxagentFreeFont(XFontStruct *fs) int nxagentFreeFont(XFontStruct *fs)
{ {
if (fs -> per_char) if (fs->per_char)
{ {
#ifdef USE_XF86BIGFONT #ifdef USE_XF86BIGFONT
_XF86BigfontFreeFontMetrics(fs); _XF86BigfontFreeFontMetrics(fs);
#else #else
free ((char *) fs->per_char); SAFE_free(fs->per_char);
#endif #endif
} }
free (fs->properties); SAFE_free(fs->properties);
SAFE_XFree(fs);
XFree(fs);
return 1; return 1;
} }
...@@ -1769,7 +1758,7 @@ char *nxagentMakeScalableFontName(const char *fontName, int scalableResolution) ...@@ -1769,7 +1758,7 @@ char *nxagentMakeScalableFontName(const char *fontName, int scalableResolution)
MakeScalableFontNameError: MakeScalableFontNameError:
free(scalableFontName); SAFE_free(scalableFontName);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "nxagentMakeScalableFontName: Invalid font name.\n"); fprintf(stderr, "nxagentMakeScalableFontName: Invalid font name.\n");
......
...@@ -61,6 +61,7 @@ is" without express or implied warranty. ...@@ -61,6 +61,7 @@ is" without express or implied warranty.
#include "Trap.h" #include "Trap.h"
#include "Screen.h" #include "Screen.h"
#include "Pixels.h" #include "Pixels.h"
#include "Utils.h"
#include "../../fb/fb.h" #include "../../fb/fb.h"
...@@ -694,7 +695,7 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -694,7 +695,7 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects)
XSetClipRectangles(nxagentDisplay, nxagentGC(pGC), pGC -> clipOrg.x, pGC -> clipOrg.y, XSetClipRectangles(nxagentDisplay, nxagentGC(pGC), pGC -> clipOrg.x, pGC -> clipOrg.y,
pRects, nRects, Unsorted); pRects, nRects, Unsorted);
free((char *) pRects); SAFE_free(pRects);
} }
break; break;
...@@ -778,7 +779,7 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -778,7 +779,7 @@ void nxagentChangeClip(GCPtr pGC, int type, void * pValue, int nRects)
pGC->clientClip = (void *) RegionFromRects(nRects, pGC->clientClip = (void *) RegionFromRects(nRects,
(xRectangle *)pValue, type); (xRectangle *)pValue, type);
free(pValue); SAFE_free(pValue);
pValue = pGC->clientClip; pValue = pGC->clientClip;
...@@ -912,9 +913,8 @@ static void nxagentFreeGCRec(struct nxagentGCRec *t) ...@@ -912,9 +913,8 @@ static void nxagentFreeGCRec(struct nxagentGCRec *t)
(void *) t, (void *) t -> gc); (void *) t, (void *) t -> gc);
#endif #endif
free(t -> gc); SAFE_free(t -> gc);
SAFE_free(t);
free(t);
} }
static void nxagentRestoreGCRec(struct nxagentGCRec *t) static void nxagentRestoreGCRec(struct nxagentGCRec *t)
...@@ -924,11 +924,11 @@ static void nxagentRestoreGCRec(struct nxagentGCRec *t) ...@@ -924,11 +924,11 @@ static void nxagentRestoreGCRec(struct nxagentGCRec *t)
(void*)t, (void*)t -> gc); (void*)t, (void*)t -> gc);
#endif #endif
free(nxagentGC(t -> pGC)); SAFE_free(nxagentGC(t -> pGC));
nxagentGC(t -> pGC) = t -> gc; nxagentGC(t -> pGC) = t -> gc;
free(t); SAFE_free(t);
} }
static void nxagentAddGCToList(GCPtr pGC) static void nxagentAddGCToList(GCPtr pGC)
...@@ -1303,7 +1303,7 @@ static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -1303,7 +1303,7 @@ static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects)
XSetClipRectangles(nxagentDisplay, nxagentGC(pGC), pGC -> clipOrg.x, pGC -> clipOrg.y, XSetClipRectangles(nxagentDisplay, nxagentGC(pGC), pGC -> clipOrg.x, pGC -> clipOrg.y,
pRects, nRects, Unsorted); pRects, nRects, Unsorted);
free((char *) pRects); SAFE_free(pRects);
} }
else else
{ {
...@@ -1374,7 +1374,7 @@ static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects) ...@@ -1374,7 +1374,7 @@ static void nxagentReconnectClip(GCPtr pGC, int type, void * pValue, int nRects)
pGC->clientClip = (void *) RegionFromRects(nRects, pGC->clientClip = (void *) RegionFromRects(nRects,
(xRectangle *)pValue, type); (xRectangle *)pValue, type);
free(pValue); SAFE_free(pValue);
pValue = pGC->clientClip; pValue = pGC->clientClip;
type = CT_REGION; type = CT_REGION;
......
...@@ -57,6 +57,7 @@ is" without express or implied warranty. ...@@ -57,6 +57,7 @@ is" without express or implied warranty.
#include "Holder.h" #include "Holder.h"
#include "Args.h" #include "Args.h"
#include "Screen.h" #include "Screen.h"
#include "Utils.h"
#include "compext/Compext.h" #include "compext/Compext.h"
...@@ -787,7 +788,7 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -787,7 +788,7 @@ RegionPtr nxagentCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
srcx, srcy, width, height); srcx, srcy, width, height);
#endif #endif
free(data); SAFE_free(data);
/* /*
* If the source is a shared memory pixmap, the * If the source is a shared memory pixmap, the
...@@ -1007,7 +1008,7 @@ RegionPtr nxagentCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, ...@@ -1007,7 +1008,7 @@ RegionPtr nxagentCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
srcx, srcy, width, height); srcx, srcy, width, height);
#endif #endif
free(data); SAFE_free(data);
/* /*
* If the source is a shared memory pixmap, the * If the source is a shared memory pixmap, the
...@@ -1545,7 +1546,7 @@ void nxagentFillPolygon(DrawablePtr pDrawable, GCPtr pGC, int shape, ...@@ -1545,7 +1546,7 @@ void nxagentFillPolygon(DrawablePtr pDrawable, GCPtr pGC, int shape,
RESET_GC_TRAP(); RESET_GC_TRAP();
} }
free(newPoints); SAFE_free(newPoints);
} }
void nxagentPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, void nxagentPolyFillRect(DrawablePtr pDrawable, GCPtr pGC,
......
...@@ -455,7 +455,7 @@ FIXME: Here the split trap is always set and so the caching of ...@@ -455,7 +455,7 @@ FIXME: Here the split trap is always set and so the caching of
if (nxagentUnpackAlpha[resource] != NULL) if (nxagentUnpackAlpha[resource] != NULL)
{ {
free(nxagentUnpackAlpha[resource] -> data); SAFE_free(nxagentUnpackAlpha[resource] -> data);
} }
else if ((nxagentUnpackAlpha[resource] = malloc(sizeof(UnpackAlphaRec))) == NULL) else if ((nxagentUnpackAlpha[resource] = malloc(sizeof(UnpackAlphaRec))) == NULL)
{ {
...@@ -463,7 +463,7 @@ FIXME: Here the split trap is always set and so the caching of ...@@ -463,7 +463,7 @@ FIXME: Here the split trap is always set and so the caching of
fprintf(stderr, "nxagentSetUnpackAlpha: PANIC! Can't allocate data for the alpha structure.\n"); fprintf(stderr, "nxagentSetUnpackAlpha: PANIC! Can't allocate data for the alpha structure.\n");
#endif #endif
free(data); SAFE_free(data);
return; return;
} }
...@@ -483,7 +483,7 @@ FIXME: Here the split trap is always set and so the caching of ...@@ -483,7 +483,7 @@ FIXME: Here the split trap is always set and so the caching of
resource, size); resource, size);
#endif #endif
free(data); SAFE_free(data);
} }
} }
...@@ -1567,20 +1567,20 @@ nxagentPutSubImageEnd: ...@@ -1567,20 +1567,20 @@ nxagentPutSubImageEnd:
nxagentImageStatistics.totalEncoded, nxagentImageStatistics.totalAdded); nxagentImageStatistics.totalEncoded, nxagentImageStatistics.totalAdded);
#endif #endif
free(packedChecksum); SAFE_free(packedChecksum);
if (packedImage != NULL) if (packedImage != NULL)
{ {
if (packedImage -> data != NULL && if (packedImage -> data != NULL &&
packedImage -> data != plainImage -> data) packedImage -> data != plainImage -> data)
{ {
free(packedImage -> data); SAFE_free(packedImage -> data);
} }
free(packedImage); SAFE_free(packedImage);
} }
free(plainImage); SAFE_free(plainImage);
} }
void nxagentGetImage(DrawablePtr pDrawable, int x, int y, int w, int h, void nxagentGetImage(DrawablePtr pDrawable, int x, int y, int w, int h,
...@@ -1634,11 +1634,8 @@ void nxagentResetAlphaCache(void) ...@@ -1634,11 +1634,8 @@ void nxagentResetAlphaCache(void)
{ {
if (nxagentUnpackAlpha[i]) if (nxagentUnpackAlpha[i])
{ {
free(nxagentUnpackAlpha[i] -> data); SAFE_free(nxagentUnpackAlpha[i] -> data);
SAFE_free(nxagentUnpackAlpha[i]);
free(nxagentUnpackAlpha[i]);
nxagentUnpackAlpha[i] = NULL;
} }
} }
} }
...@@ -1716,7 +1713,7 @@ int nxagentScaleImage(int x, int y, unsigned xRatio, unsigned yRatio, ...@@ -1716,7 +1713,7 @@ int nxagentScaleImage(int x, int y, unsigned xRatio, unsigned yRatio,
if (newImage -> data == NULL) if (newImage -> data == NULL)
{ {
free(newImage); SAFE_free(newImage);
#ifdef PANIC #ifdef PANIC
fprintf(stderr, "nxagentScaleImage: PANIC! Failed to create the target image data.\n"); fprintf(stderr, "nxagentScaleImage: PANIC! Failed to create the target image data.\n");
...@@ -1784,8 +1781,8 @@ int nxagentScaleImage(int x, int y, unsigned xRatio, unsigned yRatio, ...@@ -1784,8 +1781,8 @@ int nxagentScaleImage(int x, int y, unsigned xRatio, unsigned yRatio,
} }
} }
free((char *) image -> obdata); SAFE_free(image -> obdata);
free((char *) image); SAFE_free(image);
*pImage = newImage; *pImage = newImage;
......
...@@ -58,6 +58,7 @@ is" without express or implied warranty. ...@@ -58,6 +58,7 @@ is" without express or implied warranty.
#include "Options.h" #include "Options.h"
#include "Error.h" #include "Error.h"
#include "Init.h" #include "Init.h"
#include "Utils.h"
#include "compext/Compext.h" #include "compext/Compext.h"
...@@ -657,7 +658,7 @@ N/A ...@@ -657,7 +658,7 @@ N/A
{ {
keymap[i] = keymap64[i]; keymap[i] = keymap64[i];
} }
XFree(keymap64); SAFE_XFree(keymap64);
} }
#else /* #ifdef _XSERVER64 */ #else /* #ifdef _XSERVER64 */
...@@ -762,7 +763,7 @@ XkbError: ...@@ -762,7 +763,7 @@ XkbError:
#ifdef TEST #ifdef TEST
fprintf(stderr, "%s: changing nxagentKeyboard from [null/null] to [clone].\n", __func__); fprintf(stderr, "%s: changing nxagentKeyboard from [null/null] to [clone].\n", __func__);
#endif #endif
free(nxagentKeyboard); SAFE_free(nxagentKeyboard);
nxagentKeyboard = strdup("clone"); nxagentKeyboard = strdup("clone");
} }
...@@ -809,7 +810,7 @@ XkbError: ...@@ -809,7 +810,7 @@ XkbError:
layout = strdup(strsep(&tmp, sep)); layout = strdup(strsep(&tmp, sep));
variant = strdup(strsep(&tmp, sep)); variant = strdup(strsep(&tmp, sep));
options = strdup(strsep(&tmp, sep)); options = strdup(strsep(&tmp, sep));
free(rmlvo); SAFE_free(rmlvo);
} }
else else
{ {
...@@ -864,11 +865,11 @@ XkbError: ...@@ -864,11 +865,11 @@ XkbError:
/* Only setup keycode conversion if we are NOT in clone mode */ /* Only setup keycode conversion if we are NOT in clone mode */
if (nxagentKeyboard && (strcmp(nxagentKeyboard, "clone") == 0)) if (nxagentKeyboard && (strcmp(nxagentKeyboard, "clone") == 0))
{ {
free(rules); rules = strdup(nxagentRemoteRules); SAFE_free(rules); rules = strdup(nxagentRemoteRules);
free(model); model = strdup(nxagentRemoteModel); SAFE_free(model); model = strdup(nxagentRemoteModel);
free(layout); layout = strdup(nxagentRemoteLayout); SAFE_free(layout); layout = strdup(nxagentRemoteLayout);
free(variant); variant = strdup(nxagentRemoteVariant); SAFE_free(variant); variant = strdup(nxagentRemoteVariant);
free(options); options = strdup(nxagentRemoteOptions); SAFE_free(options); options = strdup(nxagentRemoteOptions);
/* /*
* when cloning we do not want X2Go to set the keyboard * when cloning we do not want X2Go to set the keyboard
* via a keyboard file generated by nxagent. The defined * via a keyboard file generated by nxagent. The defined
...@@ -947,9 +948,9 @@ XkbError: ...@@ -947,9 +948,9 @@ XkbError:
NXShadowInitKeymap(&(pDev->key->curKeySyms)); NXShadowInitKeymap(&(pDev->key->curKeySyms));
} }
free(rules); SAFE_free(rules);
free(variant); SAFE_free(variant);
free(options); SAFE_free(options);
} }
if (xkb) if (xkb)
...@@ -958,8 +959,8 @@ XkbError: ...@@ -958,8 +959,8 @@ XkbError:
xkb = NULL; xkb = NULL;
} }
free(model); SAFE_free(model);
free(layout); SAFE_free(layout);
#endif #endif
#ifdef WATCH #ifdef WATCH
...@@ -980,9 +981,9 @@ Reply Total Cached Bits In Bits Out Bits/Reply Ratio ...@@ -980,9 +981,9 @@ Reply Total Cached Bits In Bits Out Bits/Reply Ratio
#endif #endif
#ifdef _XSERVER64 #ifdef _XSERVER64
free(keymap); SAFE_free(keymap);
#else #else
XFree(keymap); SAFE_XFree(keymap);
#endif #endif
break; break;
case DEVICE_ON: case DEVICE_ON:
...@@ -1182,7 +1183,7 @@ int nxagentResetKeyboard(void) ...@@ -1182,7 +1183,7 @@ int nxagentResetKeyboard(void)
nxagentFreeKeyboardDeviceData(devBackup); nxagentFreeKeyboardDeviceData(devBackup);
free(devBackup); SAFE_free(devBackup);
return 1; return 1;
} }
...@@ -1315,18 +1316,15 @@ static int nxagentFreeKeyboardDeviceData(DeviceIntPtr dev) ...@@ -1315,18 +1316,15 @@ static int nxagentFreeKeyboardDeviceData(DeviceIntPtr dev)
} }
#endif #endif
free(dev->key->curKeySyms.map); SAFE_free(dev->key->curKeySyms.map);
free(dev->key->modifierKeyMap); SAFE_free(dev->key->modifierKeyMap);
free(dev->key); SAFE_free(dev->key);
dev->key = NULL;
} }
if (dev->focus) if (dev->focus)
{ {
free(dev->focus->trace); SAFE_free(dev->focus->trace);
free(dev->focus); SAFE_free(dev->focus);
dev->focus = NULL;
} }
if (dev->kbdfeed) if (dev->kbdfeed)
...@@ -1338,7 +1336,7 @@ static int nxagentFreeKeyboardDeviceData(DeviceIntPtr dev) ...@@ -1338,7 +1336,7 @@ static int nxagentFreeKeyboardDeviceData(DeviceIntPtr dev)
if (k->xkb_sli) if (k->xkb_sli)
XkbFreeSrvLedInfo(k->xkb_sli); XkbFreeSrvLedInfo(k->xkb_sli);
#endif #endif
free(k); SAFE_free(k);
} }
dev->kbdfeed = NULL; dev->kbdfeed = NULL;
} }
...@@ -1571,11 +1569,11 @@ void nxagentTuneXkbWrapper(void) ...@@ -1571,11 +1569,11 @@ void nxagentTuneXkbWrapper(void)
void nxagentXkbClearNames(void) void nxagentXkbClearNames(void)
{ {
free(nxagentRemoteRules); nxagentRemoteRules = NULL; SAFE_free(nxagentRemoteRules);
free(nxagentRemoteModel); nxagentRemoteModel = NULL; SAFE_free(nxagentRemoteModel);
free(nxagentRemoteLayout); nxagentRemoteLayout = NULL; SAFE_free(nxagentRemoteLayout);
free(nxagentRemoteVariant); nxagentRemoteVariant = NULL; SAFE_free(nxagentRemoteVariant);
free(nxagentRemoteOptions); nxagentRemoteOptions = NULL; SAFE_free(nxagentRemoteOptions);
} }
static void nxagentXkbGetNames(void) static void nxagentXkbGetNames(void)
...@@ -1618,7 +1616,7 @@ static void nxagentXkbGetNames(void) ...@@ -1618,7 +1616,7 @@ static void nxagentXkbGetNames(void)
{ {
if (data) if (data)
{ {
XFree(data); SAFE_XFree(data);
return; return;
} }
} }
...@@ -1655,7 +1653,7 @@ static void nxagentXkbGetNames(void) ...@@ -1655,7 +1653,7 @@ static void nxagentXkbGetNames(void)
name += strlen(name) + 1; name += strlen(name) + 1;
} }
XFree(data); SAFE_XFree(data);
return; return;
} }
...@@ -1686,12 +1684,12 @@ static char* getKeyboardFilePath(void) ...@@ -1686,12 +1684,12 @@ static char* getKeyboardFilePath(void)
{ {
if ((asprintf(&keyboard_file_path, "%s/keyboard", sessionpath) == -1)) if ((asprintf(&keyboard_file_path, "%s/keyboard", sessionpath) == -1))
{ {
free(sessionpath); SAFE_free(sessionpath);
FatalError("malloc for keyboard file path failed."); FatalError("malloc for keyboard file path failed.");
} }
else else
{ {
free(sessionpath); SAFE_free(sessionpath);
} }
} }
else else
...@@ -1720,7 +1718,7 @@ static void nxagentWriteKeyboardDir(void) ...@@ -1720,7 +1718,7 @@ static void nxagentWriteKeyboardDir(void)
{ {
fprintf(stderr, "Info: keyboard blocking directory created: '%s'\n", keyboard_file_path); fprintf(stderr, "Info: keyboard blocking directory created: '%s'\n", keyboard_file_path);
} }
free(keyboard_file_path); SAFE_free(keyboard_file_path);
} }
} }
...@@ -1748,7 +1746,7 @@ static void nxagentWriteKeyboardFile(char *rules, char *model, char *layout, cha ...@@ -1748,7 +1746,7 @@ static void nxagentWriteKeyboardFile(char *rules, char *model, char *layout, cha
int save_err = errno; int save_err = errno;
fprintf(stderr, "Error: keyboard file not created: %s\n", strerror(save_err)); fprintf(stderr, "Error: keyboard file not created: %s\n", strerror(save_err));
} }
free(keyboard_file_path); SAFE_free(keyboard_file_path);
} }
} }
} }
......
...@@ -294,7 +294,7 @@ void nxagentInitKeystrokes(Bool force) ...@@ -294,7 +294,7 @@ void nxagentInitKeystrokes(Bool force)
if (force) { if (force) {
if (map != default_map) if (map != default_map)
{ {
free(map); SAFE_free(map);
map = default_map; map = default_map;
} }
fprintf(stderr, "Info: re-reading keystrokes configuration\n"); fprintf(stderr, "Info: re-reading keystrokes configuration\n");
...@@ -414,7 +414,7 @@ void nxagentInitKeystrokes(Bool force) ...@@ -414,7 +414,7 @@ void nxagentInitKeystrokes(Bool force)
#endif #endif
filename = NULL; filename = NULL;
} }
free(homepath); SAFE_free(homepath);
if (map == default_map) if (map == default_map)
{ {
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include "Events.h" #include "Events.h"
#include "Holder.h" #include "Holder.h"
#include "Args.h" #include "Args.h"
#include "Utils.h"
#include "compext/Compext.h" #include "compext/Compext.h"
#include <nx/NXpack.h> #include <nx/NXpack.h>
...@@ -501,7 +502,7 @@ Bool nxagentDestroyPixmap(PixmapPtr pPixmap) ...@@ -501,7 +502,7 @@ Bool nxagentDestroyPixmap(PixmapPtr pPixmap)
FreeResource(pPixmapPriv -> mid, RT_NONE); FreeResource(pPixmapPriv -> mid, RT_NONE);
} }
free(pPixmap); SAFE_free(pPixmap);
return True; return True;
} }
...@@ -1092,7 +1093,7 @@ Bool nxagentCheckPixmapIntegrity(PixmapPtr pPixmap) ...@@ -1092,7 +1093,7 @@ Bool nxagentCheckPixmapIntegrity(PixmapPtr pPixmap)
{ {
FatalError("XGetImage: Failed.\n"); FatalError("XGetImage: Failed.\n");
free(data); SAFE_free(data);
return False; return False;
} }
...@@ -1168,7 +1169,7 @@ Bool nxagentCheckPixmapIntegrity(PixmapPtr pPixmap) ...@@ -1168,7 +1169,7 @@ Bool nxagentCheckPixmapIntegrity(PixmapPtr pPixmap)
XDestroyImage(image); XDestroyImage(image);
} }
free(data); SAFE_free(data);
} }
else else
{ {
...@@ -1265,7 +1266,7 @@ void nxagentSynchronizeShmPixmap(DrawablePtr pDrawable, int xPict, int yPict, ...@@ -1265,7 +1266,7 @@ void nxagentSynchronizeShmPixmap(DrawablePtr pDrawable, int xPict, int yPict,
nxagentPutImage(pDrawable, pGC, depth, xPict, yPict, nxagentPutImage(pDrawable, pGC, depth, xPict, yPict,
width, height, 0, format, data); width, height, 0, format, data);
free(data); SAFE_free(data);
} }
#ifdef WARNING #ifdef WARNING
else else
...@@ -1413,7 +1414,7 @@ FIXME: If the pixmap has a different depth from the window, the ...@@ -1413,7 +1414,7 @@ FIXME: If the pixmap has a different depth from the window, the
fprintf(stderr, "nxagentPixmapOnShadowDisplay: XCreateImage failed.\n"); fprintf(stderr, "nxagentPixmapOnShadowDisplay: XCreateImage failed.\n");
#endif #endif
free(data); SAFE_free(data);
return False; return False;
} }
...@@ -1572,7 +1573,7 @@ Bool nxagentFbOnShadowDisplay(void) ...@@ -1572,7 +1573,7 @@ Bool nxagentFbOnShadowDisplay(void)
fprintf(stderr, "nxagentFbOnShadowDisplay: XCreateImage failed.\n"); fprintf(stderr, "nxagentFbOnShadowDisplay: XCreateImage failed.\n");
#endif #endif
free(data); SAFE_free(data);
return False; return False;
} }
......
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
#include "Splash.h" #include "Splash.h"
#include "Error.h" #include "Error.h"
#include "Keystroke.h" #include "Keystroke.h"
#include "Utils.h"
#ifdef XKB #ifdef XKB
#include "XKBsrv.h" #include "XKBsrv.h"
...@@ -448,8 +449,7 @@ Bool nxagentReconnectSession(void) ...@@ -448,8 +449,7 @@ Bool nxagentReconnectSession(void)
return 0; return 0;
} }
free(nxagentKeyboard); SAFE_free(nxagentKeyboard);
nxagentKeyboard = NULL;
} }
nxagentSaveOptions(); nxagentSaveOptions();
...@@ -464,7 +464,7 @@ Bool nxagentReconnectSession(void) ...@@ -464,7 +464,7 @@ Bool nxagentReconnectSession(void)
fprintf(stderr, "nxagentReconnect: changing nxagentKeyboard from [null/null] to [clone].\n"); fprintf(stderr, "nxagentReconnect: changing nxagentKeyboard from [null/null] to [clone].\n");
#endif #endif
free(nxagentKeyboard); SAFE_free(nxagentKeyboard);
nxagentKeyboard = strdup("clone"); nxagentKeyboard = strdup("clone");
} }
...@@ -635,8 +635,7 @@ Bool nxagentReconnectSession(void) ...@@ -635,8 +635,7 @@ Bool nxagentReconnectSession(void)
nxagentXkbState.Initialized = 0; nxagentXkbState.Initialized = 0;
free(nxagentOldKeyboard); SAFE_free(nxagentOldKeyboard);
nxagentOldKeyboard = NULL;
nxagentInitPointerMap(); nxagentInitPointerMap();
...@@ -760,8 +759,7 @@ nxagentReconnectError: ...@@ -760,8 +759,7 @@ nxagentReconnectError:
nxagentDisconnectDisplay(); nxagentDisconnectDisplay();
} }
free(nxagentOldKeyboard); SAFE_free(nxagentOldKeyboard);
nxagentOldKeyboard = NULL;
return 0; return 0;
} }
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include "Drawable.h" #include "Drawable.h"
#include "Trap.h" #include "Trap.h"
#include "Args.h" #include "Args.h"
#include "Utils.h"
#define Atom XlibAtom #define Atom XlibAtom
#define Pixmap XlibPixmap #define Pixmap XlibPixmap
...@@ -2528,7 +2529,7 @@ void nxagentAddGlyphs(GlyphSetPtr glyphSet, Glyph *gids, xGlyphInfo *gi, ...@@ -2528,7 +2529,7 @@ void nxagentAddGlyphs(GlyphSetPtr glyphSet, Glyph *gids, xGlyphInfo *gi,
if (normalizedImages != images) if (normalizedImages != images)
{ {
free(normalizedImages); SAFE_free(normalizedImages);
} }
#ifdef DEBUG #ifdef DEBUG
...@@ -2636,7 +2637,7 @@ FIXME: Is this useful or just a waste of bandwidth? ...@@ -2636,7 +2637,7 @@ FIXME: Is this useful or just a waste of bandwidth?
nparams); nparams);
#endif #endif
free(szFilter); SAFE_free(szFilter);
} }
......
...@@ -281,10 +281,7 @@ Bool nxagentRootlessTreesMatch(void) ...@@ -281,10 +281,7 @@ Bool nxagentRootlessTreesMatch(void)
} }
} }
if (children_return) SAFE_XFree(children_return);
{
XFree(children_return);
}
return treesMatch; return treesMatch;
} }
...@@ -332,7 +329,7 @@ void nxagentRootlessRestack(unsigned long children[], unsigned int nchildren) ...@@ -332,7 +329,7 @@ void nxagentRootlessRestack(unsigned long children[], unsigned int nchildren)
if (!ntoplevel) if (!ntoplevel)
{ {
free(toplevel); SAFE_free(toplevel);
return; return;
} }
...@@ -397,7 +394,7 @@ void nxagentRootlessRestack(unsigned long children[], unsigned int nchildren) ...@@ -397,7 +394,7 @@ void nxagentRootlessRestack(unsigned long children[], unsigned int nchildren)
#endif #endif
free(toplevel); SAFE_free(toplevel);
return; return;
} }
...@@ -818,7 +815,7 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value) ...@@ -818,7 +815,7 @@ int nxagentExportProperty(pWin, property, type, format, mode, nUnits, value)
if (freeMem) if (freeMem)
{ {
free(output); SAFE_free(output);
} }
return export; return export;
...@@ -1131,7 +1128,7 @@ void nxagentImportProperty(Window window, ...@@ -1131,7 +1128,7 @@ void nxagentImportProperty(Window window,
if (freeMem) if (freeMem)
{ {
free(output); SAFE_free(output);
} }
return; return;
...@@ -1183,7 +1180,7 @@ void nxagentRemovePropertyFromList(void) ...@@ -1183,7 +1180,7 @@ void nxagentRemovePropertyFromList(void)
nxagentPropertyList.last = NULL; nxagentPropertyList.last = NULL;
} }
free(tmp); SAFE_free(tmp);
} }
} }
......
...@@ -302,8 +302,7 @@ Bool nxagentIsParentOf(Display *d, XlibWindow possible_parent, XlibWindow candid ...@@ -302,8 +302,7 @@ Bool nxagentIsParentOf(Display *d, XlibWindow possible_parent, XlibWindow candid
if (XQueryTree(d, candidate, &root, &parent, &children, &num_children)) if (XQueryTree(d, candidate, &root, &parent, &children, &num_children))
{ {
if (children) SAFE_XFree(children);
XFree((char *)children);
#ifdef TEST #ifdef TEST
fprintf(stderr, "%s: parent of full screen window [%p] root [%p] possible_parent [%p] candidate [%p]\n", __func__, parent, root, possible_parent, candidate); fprintf(stderr, "%s: parent of full screen window [%p] root [%p] possible_parent [%p] candidate [%p]\n", __func__, parent, root, possible_parent, candidate);
...@@ -484,11 +483,8 @@ Window nxagentCreateIconWindow(void) ...@@ -484,11 +483,8 @@ Window nxagentCreateIconWindow(void)
window_name, window_name, window_name, window_name,
NULL , 0 , sizeHints, wmHints, NULL); NULL , 0 , sizeHints, wmHints, NULL);
if (sizeHints) SAFE_XFree(sizeHints);
XFree(sizeHints); SAFE_XFree(wmHints);
if (wmHints)
XFree(wmHints);
/* /*
* Enable events from the icon window. * Enable events from the icon window.
...@@ -889,10 +885,9 @@ void freeDepths(DepthPtr depths, int num) ...@@ -889,10 +885,9 @@ void freeDepths(DepthPtr depths, int num)
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "%s: freeing depth [%d] index [%d] vids [%p]\n", __func__, depths[i].depth, i, (void*) depths[i].vids); fprintf(stderr, "%s: freeing depth [%d] index [%d] vids [%p]\n", __func__, depths[i].depth, i, (void*) depths[i].vids);
#endif #endif
free(depths[i].vids); SAFE_free(depths[i].vids);
depths[i].vids = NULL;
} }
free(depths); SAFE_free(depths);
} }
Bool nxagentOpenScreen(ScreenPtr pScreen, Bool nxagentOpenScreen(ScreenPtr pScreen,
...@@ -1387,7 +1382,7 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, ...@@ -1387,7 +1382,7 @@ Bool nxagentOpenScreen(ScreenPtr pScreen,
if (!pFrameBufferBits) if (!pFrameBufferBits)
{ {
freeDepths(depths, numDepths); freeDepths(depths, numDepths);
free(visuals); SAFE_free(visuals);
return FALSE; return FALSE;
} }
...@@ -1410,7 +1405,7 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, ...@@ -1410,7 +1405,7 @@ Bool nxagentOpenScreen(ScreenPtr pScreen,
monitorResolution, monitorResolution, PixmapBytePad(nxagentOption(RootWidth), rootDepth), bitsPerPixel)) monitorResolution, monitorResolution, PixmapBytePad(nxagentOption(RootWidth), rootDepth), bitsPerPixel))
{ {
freeDepths(depths, numDepths); freeDepths(depths, numDepths);
free(visuals); SAFE_free(visuals);
return FALSE; return FALSE;
} }
...@@ -1451,7 +1446,7 @@ Bool nxagentOpenScreen(ScreenPtr pScreen, ...@@ -1451,7 +1446,7 @@ Bool nxagentOpenScreen(ScreenPtr pScreen,
pScreen -> numDepths = numDepths; pScreen -> numDepths = numDepths;
pScreen -> rootDepth = rootDepth; pScreen -> rootDepth = rootDepth;
free(pScreen -> visuals); SAFE_free(pScreen -> visuals);
pScreen -> visuals = visuals; pScreen -> visuals = visuals;
pScreen -> numVisuals = numVisuals; pScreen -> numVisuals = numVisuals;
pScreen -> rootVisual = defaultVisual; pScreen -> rootVisual = defaultVisual;
...@@ -1892,8 +1887,8 @@ N/A ...@@ -1892,8 +1887,8 @@ N/A
hint.res_class = strdup("NXAgent"); hint.res_class = strdup("NXAgent");
} }
XSetClassHint(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum], &hint); XSetClassHint(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum], &hint);
free(hint.res_name); SAFE_free(hint.res_name);
free(hint.res_class); SAFE_free(hint.res_class);
} }
if (nxagentOption(Fullscreen)) if (nxagentOption(Fullscreen))
...@@ -1977,17 +1972,8 @@ N/A ...@@ -1977,17 +1972,8 @@ N/A
nxagentWindowName, nxagentWindowName,
argv , argc , sizeHints, wmHints, NULL); argv , argc , sizeHints, wmHints, NULL);
if (sizeHints) SAFE_XFree(sizeHints);
{ SAFE_XFree(wmHints);
XFree(sizeHints);
sizeHints = NULL;
}
if (wmHints)
{
XFree(wmHints);
wmHints = NULL;
}
/* /*
* Clear the window but let it unmapped. We'll map it * Clear the window but let it unmapped. We'll map it
...@@ -2199,9 +2185,9 @@ Bool nxagentCloseScreen(ScreenPtr pScreen) ...@@ -2199,9 +2185,9 @@ Bool nxagentCloseScreen(ScreenPtr pScreen)
* Free the frame buffer. * Free the frame buffer.
*/ */
free(((PixmapPtr)pScreen -> devPrivate) -> devPrivate.ptr); SAFE_free(((PixmapPtr)pScreen -> devPrivate) -> devPrivate.ptr);
free(pScreen->devPrivate);pScreen->devPrivate = NULL; SAFE_free(pScreen->devPrivate);
free(pScreen->visuals); pScreen->visuals = NULL; SAFE_free(pScreen->visuals);
fbCloseScreen(pScreen); fbCloseScreen(pScreen);
...@@ -3158,7 +3144,7 @@ int nxagentShadowPoll(PixmapPtr nxagentShadowPixmapPtr, GCPtr nxagentShadowGCPtr ...@@ -3158,7 +3144,7 @@ int nxagentShadowPoll(PixmapPtr nxagentShadowPixmapPtr, GCPtr nxagentShadowGCPtr
length = nxagentImageLength(width, height, ZPixmap, 0, nxagentMasterDepth); length = nxagentImageLength(width, height, ZPixmap, 0, nxagentMasterDepth);
free(tBuffer); SAFE_free(tBuffer);
tBuffer = malloc(length); tBuffer = malloc(length);
...@@ -3215,7 +3201,7 @@ int nxagentShadowPoll(PixmapPtr nxagentShadowPixmapPtr, GCPtr nxagentShadowGCPtr ...@@ -3215,7 +3201,7 @@ int nxagentShadowPoll(PixmapPtr nxagentShadowPixmapPtr, GCPtr nxagentShadowGCPtr
RegionUnion(&nxagentShadowUpdateRegion, &nxagentShadowUpdateRegion, &updateRegion); RegionUnion(&nxagentShadowUpdateRegion, &nxagentShadowUpdateRegion, &updateRegion);
} }
free(tBuffer); SAFE_free(tBuffer);
RegionUninit(&updateRegion); RegionUninit(&updateRegion);
} }
...@@ -3433,7 +3419,7 @@ void nxagentShadowAdaptDepth(unsigned int width, unsigned int height, ...@@ -3433,7 +3419,7 @@ void nxagentShadowAdaptDepth(unsigned int width, unsigned int height,
cBuffer = (unsigned char *) *buffer; cBuffer = (unsigned char *) *buffer;
*buffer = (char *) icBuffer; *buffer = (char *) icBuffer;
free(cBuffer); SAFE_free(cBuffer);
} }
#ifdef NXAGENT_ARTSD #ifdef NXAGENT_ARTSD
...@@ -3616,7 +3602,7 @@ FIXME: The port information is not used at the moment and produces a ...@@ -3616,7 +3602,7 @@ FIXME: The port information is not used at the moment and produces a
strlen(local_buf), local_buf, 1); strlen(local_buf), local_buf, 1);
} }
free(local_buf); SAFE_free(local_buf);
} }
} }
} }
...@@ -4040,7 +4026,7 @@ int nxagentAdjustRandRXinerama(ScreenPtr pScreen) ...@@ -4040,7 +4026,7 @@ int nxagentAdjustRandRXinerama(ScreenPtr pScreen)
#endif #endif
number = 1; number = 1;
free(screeninfo); SAFE_free(screeninfo);
if (!(screeninfo = malloc(sizeof(XineramaScreenInfo)))) { if (!(screeninfo = malloc(sizeof(XineramaScreenInfo)))) {
return FALSE; return FALSE;
...@@ -4309,8 +4295,7 @@ int nxagentAdjustRandRXinerama(ScreenPtr pScreen) ...@@ -4309,8 +4295,7 @@ int nxagentAdjustRandRXinerama(ScreenPtr pScreen)
} }
/* release allocated memory */ /* release allocated memory */
free(screeninfo); SAFE_free(screeninfo);
screeninfo = NULL;
#ifdef DEBUG #ifdef DEBUG
for (i = 0; i < pScrPriv->numCrtcs; i++) { for (i = 0; i < pScrPriv->numCrtcs; i++) {
...@@ -4425,7 +4410,7 @@ void nxagentSaveAreas(PixmapPtr pPixmap, RegionPtr prgnSave, int xorg, int yorg, ...@@ -4425,7 +4410,7 @@ void nxagentSaveAreas(PixmapPtr pPixmap, RegionPtr prgnSave, int xorg, int yorg,
XSetClipRectangles(nxagentDisplay, gc, 0, 0, pRects, nRects, Unsorted); XSetClipRectangles(nxagentDisplay, gc, 0, 0, pRects, nRects, Unsorted);
free((char *) pRects); SAFE_free(pRects);
extents = *RegionExtents(&cleanRegion); extents = *RegionExtents(&cleanRegion);
...@@ -4571,7 +4556,7 @@ void nxagentRestoreAreas(PixmapPtr pPixmap, RegionPtr prgnRestore, int xorg, ...@@ -4571,7 +4556,7 @@ void nxagentRestoreAreas(PixmapPtr pPixmap, RegionPtr prgnRestore, int xorg,
XSetClipRectangles(nxagentDisplay, gc, 0, 0, pRects, nRects, Unsorted); XSetClipRectangles(nxagentDisplay, gc, 0, 0, pRects, nRects, Unsorted);
free(pRects); SAFE_free(pRects);
extents = *RegionExtents(clipRegion); extents = *RegionExtents(clipRegion);
...@@ -4651,7 +4636,7 @@ void nxagentSetWMNormalHints(int screen, int width, int height) ...@@ -4651,7 +4636,7 @@ void nxagentSetWMNormalHints(int screen, int width, int height)
XSetWMNormalHints(nxagentDisplay, nxagentDefaultWindows[screen], sizeHints); XSetWMNormalHints(nxagentDisplay, nxagentDefaultWindows[screen], sizeHints);
XFree(sizeHints); SAFE_XFree(sizeHints);
} }
/* /*
...@@ -4670,7 +4655,7 @@ void nxagentSetWMNormalHintsMaxsize(ScreenPtr pScreen, int maxwidth, int maxheig ...@@ -4670,7 +4655,7 @@ void nxagentSetWMNormalHintsMaxsize(ScreenPtr pScreen, int maxwidth, int maxheig
sizeHints->max_height = maxheight; sizeHints->max_height = maxheight;
XSetWMNormalHints(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum], XSetWMNormalHints(nxagentDisplay, nxagentDefaultWindows[pScreen->myNum],
sizeHints); sizeHints);
XFree(sizeHints); SAFE_XFree(sizeHints);
} }
} }
...@@ -4811,7 +4796,7 @@ FIXME ...@@ -4811,7 +4796,7 @@ FIXME
fprintf(stderr, "nxagentShowPixmap: XGetImage failed.\n"); fprintf(stderr, "nxagentShowPixmap: XGetImage failed.\n");
#endif #endif
free(data); SAFE_free(data);
return; return;
} }
...@@ -4844,7 +4829,7 @@ FIXME ...@@ -4844,7 +4829,7 @@ FIXME
XDestroyImage(image); XDestroyImage(image);
} }
free(data); SAFE_free(data);
/* /*
FIXME FIXME
...@@ -4896,7 +4881,7 @@ void nxagentFbRestoreArea(PixmapPtr pPixmap, WindowPtr pWin, int xSrc, int ySrc, ...@@ -4896,7 +4881,7 @@ void nxagentFbRestoreArea(PixmapPtr pPixmap, WindowPtr pWin, int xSrc, int ySrc,
fprintf(stderr, "nxagentFbRestoreArea: XGetImage failed.\n"); fprintf(stderr, "nxagentFbRestoreArea: XGetImage failed.\n");
#endif #endif
free(data); SAFE_free(data);
return; return;
} }
...@@ -4956,7 +4941,7 @@ FIXME ...@@ -4956,7 +4941,7 @@ FIXME
/* /*
FIXME FIXME
free(data); SAFE_free(data);
*/ */
} }
......
...@@ -45,5 +45,6 @@ static inline const char * validateString(const char *str) { ...@@ -45,5 +45,6 @@ static inline const char * validateString(const char *str) {
} }
#define SAFE_XFree(what) do {if (what) {XFree(what); what = NULL;}} while (0) #define SAFE_XFree(what) do {if (what) {XFree(what); what = NULL;}} while (0)
#define SAFE_free(what) do {free(what); what = NULL;} while (0)
#endif /* __Utils_H__ */ #endif /* __Utils_H__ */
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
#include "Init.h" #include "Init.h"
#include "Composite.h" #include "Composite.h"
#include "Events.h" #include "Events.h"
#include "Utils.h"
#include <nx/NX.h> #include <nx/NX.h>
#include "compext/Compext.h" #include "compext/Compext.h"
...@@ -1430,10 +1431,7 @@ void nxagentConfigureWindow(WindowPtr pWin, unsigned int mask) ...@@ -1430,10 +1431,7 @@ void nxagentConfigureWindow(WindowPtr pWin, unsigned int mask)
fprintf(stderr, "nxagentConfigureWindow: Failed QueryTree request.\n "); fprintf(stderr, "nxagentConfigureWindow: Failed QueryTree request.\n ");
} }
if (children_return) SAFE_XFree(children_return);
{
XFree(children_return);
}
} }
#endif #endif
} }
...@@ -3129,7 +3127,7 @@ static void nxagentReconnectWindow(void * param0, XID param1, void * data_buffer ...@@ -3129,7 +3127,7 @@ static void nxagentReconnectWindow(void * param0, XID param1, void * data_buffer
&hints); &hints);
#ifdef _XSERVER64 #ifdef _XSERVER64
free(data64); SAFE_free(data64);
#endif #endif
} }
} }
...@@ -3376,7 +3374,7 @@ Bool nxagentCheckWindowIntegrity(WindowPtr pWin) ...@@ -3376,7 +3374,7 @@ Bool nxagentCheckWindowIntegrity(WindowPtr pWin)
XDestroyImage(image); XDestroyImage(image);
} }
free(data); SAFE_free(data);
} }
else else
{ {
...@@ -3465,14 +3463,14 @@ void nxagentFlushConfigureWindow(void) ...@@ -3465,14 +3463,14 @@ void nxagentFlushConfigureWindow(void)
if (index == nxagentConfiguredWindowList) if (index == nxagentConfiguredWindowList)
{ {
free(index); SAFE_free(index);
break; break;
} }
else else
{ {
ConfiguredWindowStruct *tmp = index; ConfiguredWindowStruct *tmp = index;
index = index -> prev; index = index -> prev;
free(tmp); SAFE_free(tmp);
} }
} }
...@@ -3622,16 +3620,14 @@ void nxagentDeleteConfiguredWindow(WindowPtr pWin) ...@@ -3622,16 +3620,14 @@ void nxagentDeleteConfiguredWindow(WindowPtr pWin)
{ {
if (index -> prev == NULL && index -> next == NULL) if (index -> prev == NULL && index -> next == NULL)
{ {
free(nxagentConfiguredWindowList); SAFE_free(nxagentConfiguredWindowList);
nxagentConfiguredWindowList = NULL;
return; return;
} }
else if (index -> prev == NULL) else if (index -> prev == NULL)
{ {
tmp = nxagentConfiguredWindowList; tmp = nxagentConfiguredWindowList;
index = nxagentConfiguredWindowList = tmp -> next; index = nxagentConfiguredWindowList = tmp -> next;
free(tmp); SAFE_free(tmp);
nxagentConfiguredWindowList -> prev = NULL; nxagentConfiguredWindowList -> prev = NULL;
continue; continue;
...@@ -3640,7 +3636,7 @@ void nxagentDeleteConfiguredWindow(WindowPtr pWin) ...@@ -3640,7 +3636,7 @@ void nxagentDeleteConfiguredWindow(WindowPtr pWin)
{ {
tmp = index; tmp = index;
index = index -> prev; index = index -> prev;
free(tmp); SAFE_free(tmp);
index -> next = NULL; index -> next = NULL;
return; return;
...@@ -3651,7 +3647,7 @@ void nxagentDeleteConfiguredWindow(WindowPtr pWin) ...@@ -3651,7 +3647,7 @@ void nxagentDeleteConfiguredWindow(WindowPtr pWin)
index = index -> next; index = index -> next;
previous -> next = index; previous -> next = index;
index -> prev = previous; index -> prev = previous;
free(tmp); SAFE_free(tmp);
continue; continue;
} }
...@@ -3693,16 +3689,14 @@ void nxagentDeleteStaticResizedWindow(unsigned long sequence) ...@@ -3693,16 +3689,14 @@ void nxagentDeleteStaticResizedWindow(unsigned long sequence)
{ {
if (index -> prev == NULL && index -> next == NULL) if (index -> prev == NULL && index -> next == NULL)
{ {
free(nxagentStaticResizedWindowList); SAFE_free(nxagentStaticResizedWindowList);
nxagentStaticResizedWindowList = NULL;
return; return;
} }
else if (index -> prev == NULL) else if (index -> prev == NULL)
{ {
tmp = nxagentStaticResizedWindowList; tmp = nxagentStaticResizedWindowList;
index = nxagentStaticResizedWindowList = tmp -> next; index = nxagentStaticResizedWindowList = tmp -> next;
free(tmp); SAFE_free(tmp);
nxagentStaticResizedWindowList -> prev = NULL; nxagentStaticResizedWindowList -> prev = NULL;
continue; continue;
...@@ -3711,7 +3705,7 @@ void nxagentDeleteStaticResizedWindow(unsigned long sequence) ...@@ -3711,7 +3705,7 @@ void nxagentDeleteStaticResizedWindow(unsigned long sequence)
{ {
tmp = index; tmp = index;
index = index -> prev; index = index -> prev;
free(tmp); SAFE_free(tmp);
index -> next = NULL; index -> next = NULL;
return; return;
...@@ -3722,7 +3716,7 @@ void nxagentDeleteStaticResizedWindow(unsigned long sequence) ...@@ -3722,7 +3716,7 @@ void nxagentDeleteStaticResizedWindow(unsigned long sequence)
index = index -> next; index = index -> next;
previous -> next = index; previous -> next = index;
index -> prev = previous; index -> prev = previous;
free(tmp); SAFE_free(tmp);
continue; continue;
} }
...@@ -3855,8 +3849,7 @@ int nxagentRemoveItemBSPixmapList(unsigned long pixmapId) ...@@ -3855,8 +3849,7 @@ int nxagentRemoveItemBSPixmapList(unsigned long pixmapId)
if ((nxagentBSPixmapList[i] != NULL) && if ((nxagentBSPixmapList[i] != NULL) &&
(nxagentBSPixmapList[i] -> storingPixmapId == pixmapId)) (nxagentBSPixmapList[i] -> storingPixmapId == pixmapId))
{ {
free(nxagentBSPixmapList[i]); SAFE_free(nxagentBSPixmapList[i]);
nxagentBSPixmapList[i] = NULL;
if (i < BSPIXMAPLIMIT - 1) if (i < BSPIXMAPLIMIT - 1)
{ {
...@@ -3894,8 +3887,7 @@ int nxagentEmptyBSPixmapList(void) ...@@ -3894,8 +3887,7 @@ int nxagentEmptyBSPixmapList(void)
{ {
for (int i = 0; i < BSPIXMAPLIMIT; i++) for (int i = 0; i < BSPIXMAPLIMIT; i++)
{ {
free(nxagentBSPixmapList[i]); SAFE_free(nxagentBSPixmapList[i]);
nxagentBSPixmapList[i] = NULL;
} }
return 1; return 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment