Commit 0a4d8cbd authored by Mikhail Gusarov's avatar Mikhail Gusarov

Remove more superfluous if(p) checks around free(p)

This patch has been generated by the following Coccinelle semantic patch:

@@
expression E;
@@

-if(E) { free(E); }
+free(E);
Signed-off-by: default avatarMikhail Gusarov <dottedmag@dottedmag.net>
Reviewed-by: Julien Cristau's avatarJulien Cristau <jcristau@debian.org>
Reviewed-by: default avatarFernando Carrijo <fcarrijo@yahoo.com.br>
Reviewed-by: default avatarMatt Turner <mattst88@gmail.com>
parent 5a0fc0ad
......@@ -1276,8 +1276,7 @@ XineramaGetImageData(
}
if(ScratchMem)
free(ScratchMem);
free(ScratchMem);
RegionUninit(&SrcRegion);
RegionUninit(&GrabRegion);
......
......@@ -604,7 +604,7 @@ bailout:
if (removeAuth)
RemoveAuthorization(stuff->nbytesAuthProto, protoname,
authdata_len, pAuthdata);
if (pAuth) free(pAuth);
free(pAuth);
return err;
} /* ProcSecurityGenerateAuthorization */
......
......@@ -323,7 +323,7 @@ XaceCensorImage(
*/
memset(pBuf, 0, (int)(widthBytesLine * h));
}
if (pRects) free(pRects);
free(pRects);
if (pScratchGC) FreeScratchGC(pScratchGC);
if (pPix) FreeScratchPixmapHeader(pPix);
}
......
......@@ -259,8 +259,7 @@ ProcXvMCCreateContext(ClientPtr client)
WriteToClient(client, dwords << 2, (char*)data);
AddResource(pContext->context_id, XvMCRTContext, pContext);
if(data)
free(data);
free(data);
return Success;
}
......@@ -327,8 +326,7 @@ ProcXvMCCreateSurface(ClientPtr client)
WriteToClient(client, dwords << 2, (char*)data);
AddResource(pSurface->surface_id, XvMCRTSurface, pSurface);
if(data)
free(data);
free(data);
pContext->refcnt++;
......@@ -444,8 +442,7 @@ ProcXvMCCreateSubpicture(ClientPtr client)
WriteToClient(client, dwords << 2, (char*)data);
AddResource(pSubpicture->subpicture_id, XvMCRTSubpicture, pSubpicture);
if(data)
free(data);
free(data);
pContext->refcnt++;
......
......@@ -153,8 +153,7 @@ ProcXGetDeviceMotionEvents(ClientPtr client)
}
WriteToClient(client, length * 4, (char *)coords);
}
if (coords)
free(coords);
free(coords);
return Success;
}
......
......@@ -622,8 +622,7 @@ XIFetchDeviceProperty(DeviceIntPtr dev, Atom property)
static void
XIDestroyDeviceProperty (XIPropertyPtr prop)
{
if (prop->value.data)
free(prop->value.data);
free(prop->value.data);
free(prop);
}
......@@ -798,8 +797,7 @@ XIChangeDeviceProperty (DeviceIntPtr dev, Atom property, Atom type,
&new_value, checkonly);
if (checkonly && rc != Success)
{
if (new_value.data)
free(new_value.data);
free(new_value.data);
return (rc);
}
}
......@@ -808,8 +806,7 @@ XIChangeDeviceProperty (DeviceIntPtr dev, Atom property, Atom type,
checkonly = !checkonly;
} while (!checkonly);
}
if (prop_value->data)
free(prop_value->data);
free(prop_value->data);
*prop_value = new_value;
} else if (len == 0)
{
......
......@@ -184,10 +184,8 @@ unwind:
while (options) {
tmpo = options;
options = options->next;
if (tmpo->key)
free(tmpo->key);
if (tmpo->value)
free(tmpo->value);
free(tmpo->key);
free(tmpo->value);
free(tmpo);
}
......
......@@ -251,28 +251,23 @@ device_added(LibHalContext *hal_ctx, const char *udi)
{
if (!strcasecmp(&tmp[3], "layout"))
{
if (xkb_opts.layout)
free(xkb_opts.layout);
free(xkb_opts.layout);
xkb_opts.layout = strdup(tmp_val);
} else if (!strcasecmp(&tmp[3], "model"))
{
if (xkb_opts.model)
free(xkb_opts.model);
free(xkb_opts.model);
xkb_opts.model = strdup(tmp_val);
} else if (!strcasecmp(&tmp[3], "rules"))
{
if (xkb_opts.rules)
free(xkb_opts.rules);
free(xkb_opts.rules);
xkb_opts.rules = strdup(tmp_val);
} else if (!strcasecmp(&tmp[3], "variant"))
{
if (xkb_opts.variant)
free(xkb_opts.variant);
free(xkb_opts.variant);
xkb_opts.variant = strdup(tmp_val);
} else if (!strcasecmp(&tmp[3], "options"))
{
if (xkb_opts.options)
free(xkb_opts.options);
free(xkb_opts.options);
xkb_opts.options = strdup(tmp_val);
}
} else
......@@ -289,8 +284,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
(!strcasecmp(&tmp[3], "options")) &&
(tmp_val = get_prop_string_array(hal_ctx, udi, psi_key)))
{
if (xkb_opts.options)
free(xkb_opts.options);
free(xkb_opts.options);
xkb_opts.options = strdup(tmp_val);
}
}
......@@ -366,22 +360,17 @@ device_added(LibHalContext *hal_ctx, const char *udi)
}
for (; dev; dev = dev->next){
if (dev->config_info)
free(dev->config_info);
free(dev->config_info);
dev->config_info = xstrdup(config_info);
}
unwind:
if (set)
libhal_free_property_set(set);
if (path)
free(path);
if (driver)
free(driver);
if (name)
free(name);
if (config_info)
free(config_info);
free(path);
free(driver);
free(name);
free(config_info);
while (!dev && (tmpo = options)) {
options = tmpo->next;
free(tmpo->key);
......@@ -401,16 +390,11 @@ unwind:
free(attrs.tags);
}
if (xkb_opts.layout)
free(xkb_opts.layout);
if (xkb_opts.rules)
free(xkb_opts.rules);
if (xkb_opts.model)
free(xkb_opts.model);
if (xkb_opts.variant)
free(xkb_opts.variant);
if (xkb_opts.options)
free(xkb_opts.options);
free(xkb_opts.layout);
free(xkb_opts.rules);
free(xkb_opts.model);
free(xkb_opts.variant);
free(xkb_opts.options);
dbus_error_free(&error);
......
......@@ -693,10 +693,7 @@ ProcDbeGetVisualInfo(ClientPtr client)
if (!(pScrVisInfo = (XdbeScreenVisualInfo *)malloc(count *
sizeof(XdbeScreenVisualInfo))))
{
if (pDrawables)
{
free(pDrawables);
}
free(pDrawables);
return(BadAlloc);
}
......@@ -722,10 +719,7 @@ ProcDbeGetVisualInfo(ClientPtr client)
}
/* Free pDrawables if we needed to allocate it above. */
if (pDrawables)
{
free(pDrawables);
}
free(pDrawables);
return (rc == Success) ? BadAlloc : rc;
}
......@@ -803,10 +797,7 @@ ProcDbeGetVisualInfo(ClientPtr client)
}
free(pScrVisInfo);
if (pDrawables)
{
free(pDrawables);
}
free(pDrawables);
return Success;
......
......@@ -1639,8 +1639,7 @@ AllocColorCells (int client, ColormapPtr pmap, int colors, int planes,
pcr->client = client;
if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer)pcr))
ok = BadAlloc;
} else if (pcr)
free(pcr);
} else free(pcr);
return (ok);
}
......@@ -1730,8 +1729,7 @@ AllocColorPlanes (int client, ColormapPtr pmap, int colors,
pcr->client = client;
if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer)pcr))
ok = BadAlloc;
} else if (pcr)
free(pcr);
} else free(pcr);
return (ok);
}
......@@ -1764,9 +1762,9 @@ AllocDirect (int client, ColormapPtr pmap, int c, int r, int g, int b, Bool cont
ppixBlue = malloc(npixB * sizeof(Pixel));
if (!ppixRed || !ppixGreen || !ppixBlue)
{
if (ppixBlue) free(ppixBlue);
if (ppixGreen) free(ppixGreen);
if (ppixRed) free(ppixRed);
free(ppixBlue);
free(ppixGreen);
free(ppixRed);
return(BadAlloc);
}
......
......@@ -740,8 +740,7 @@ FreeDeviceClass(int type, pointer *class)
case ButtonClass:
{
ButtonClassPtr *b = (ButtonClassPtr*)class;
if ((*b)->xkb_acts)
free((*b)->xkb_acts);
free((*b)->xkb_acts);
free((*b));
break;
}
......@@ -749,8 +748,7 @@ FreeDeviceClass(int type, pointer *class)
{
ValuatorClassPtr *v = (ValuatorClassPtr*)class;
if ((*v)->motion)
free((*v)->motion);
free((*v)->motion);
free((*v));
break;
}
......@@ -1465,10 +1463,8 @@ InitStringFeedbackClassDeviceStruct (
feedc->ctrl.symbols_displayed = malloc(sizeof (KeySym) * max_symbols);
if (!feedc->ctrl.symbols_supported || !feedc->ctrl.symbols_displayed)
{
if (feedc->ctrl.symbols_supported)
free(feedc->ctrl.symbols_supported);
if (feedc->ctrl.symbols_displayed)
free(feedc->ctrl.symbols_displayed);
free(feedc->ctrl.symbols_supported);
free(feedc->ctrl.symbols_displayed);
free(feedc);
return FALSE;
}
......@@ -2283,8 +2279,7 @@ ProcGetMotionEvents(ClientPtr client)
WriteSwappedDataToClient(client, nEvents * sizeof(xTimecoord),
(char *)coords);
}
if (coords)
free(coords);
free(coords);
return Success;
}
......
......@@ -2837,7 +2837,7 @@ ProcQueryColors(ClientPtr client)
return(BadAlloc);
if( (rc = QueryColors(pcmp, count, (Pixel *)&stuff[1], prgbs, client)) )
{
if (prgbs) free(prgbs);
free(prgbs);
return rc;
}
memset(&qcr, 0, sizeof(xQueryColorsReply));
......@@ -2851,7 +2851,7 @@ ProcQueryColors(ClientPtr client)
client->pSwapReplyFunc = (ReplySwapPtr) SQColorsExtend;
WriteSwappedDataToClient(client, count * sizeof(xrgb), prgbs);
}
if (prgbs) free(prgbs);
free(prgbs);
return Success;
}
......
......@@ -677,7 +677,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
return TRUE;
}
if (err == FontNameAlias) {
if (resolved) free(resolved);
free(resolved);
resolved = malloc(resolvedlen + 1);
if (resolved)
memmove(resolved, tmpname, resolvedlen + 1);
......@@ -731,8 +731,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
{
c->saved = c->current;
c->haveSaved = TRUE;
if (c->savedName)
free(c->savedName);
free(c->savedName);
c->savedName = malloc(namelen + 1);
if (c->savedName)
memmove(c->savedName, name, namelen + 1);
......@@ -828,10 +827,10 @@ bail:
for (i = 0; i < c->num_fpes; i++)
FreeFPE(c->fpe_list[i]);
free(c->fpe_list);
if (c->savedName) free(c->savedName);
free(c->savedName);
FreeFontNames(names);
free(c);
if (resolved) free(resolved);
free(resolved);
return TRUE;
}
......@@ -994,8 +993,7 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c)
c->saved = c->current;
c->haveSaved = TRUE;
c->savedNumFonts = numFonts;
if (c->savedName)
free(c->savedName);
free(c->savedName);
c->savedName = malloc(namelen + 1);
if (c->savedName)
memmove(c->savedName, name, namelen + 1);
......@@ -1106,7 +1104,7 @@ bail:
FreeFPE(c->fpe_list[i]);
free(c->reply);
free(c->fpe_list);
if (c->savedName) free(c->savedName);
free(c->savedName);
free(c);
return TRUE;
}
......
......@@ -893,7 +893,7 @@ InitCallbackManager(void)
{
DeleteCallbackList(listsToCleanup[i]);
}
if (listsToCleanup) free(listsToCleanup);
free(listsToCleanup);
numCallbackListsToCleanup = 0;
listsToCleanup = NULL;
......
......@@ -3793,10 +3793,8 @@ DeliverFocusedEvent(DeviceIntPtr keybd, InternalEvent *event, WindowPtr window)
}
unwind:
if (xE)
free(xE);
if (xi2)
free(xi2);
free(xE);
free(xi2);
return;
}
......@@ -3976,10 +3974,8 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev,
}
}
if (xi)
free(xi);
if (xi2)
free(xi2);
free(xi);
free(xi2);
}
/* This function is used to set the key pressed or key released state -
......
......@@ -327,8 +327,7 @@ void
AllocateMotionHistory(DeviceIntPtr pDev)
{
int size;
if (pDev->valuator->motion)
free(pDev->valuator->motion);
free(pDev->valuator->motion);
if (pDev->valuator->numMotionEvents < 1)
return;
......
......@@ -441,10 +441,10 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab)
details = malloc(i * sizeof(Mask *));
if (!deletes || !adds || !updates || !details)
{
if (details) free(details);
if (updates) free(updates);
if (adds) free(adds);
if (deletes) free(deletes);
free(details);
free(updates);
free(adds);
free(deletes);
return FALSE;
}
......
......@@ -762,8 +762,7 @@ RegionOp(
AppendRegions(newReg, r2BandEnd, r2End);
}
if (oldData)
free(oldData);
free(oldData);
if (!(numRects = newReg->data->numRects))
{
......
......@@ -257,8 +257,7 @@ exaDestroyPixmap_mixed(PixmapPtr pPixmap)
pExaPixmap->driverPriv = NULL;
if (pExaPixmap->pDamage) {
if (pExaPixmap->sys_ptr)
free(pExaPixmap->sys_ptr);
free(pExaPixmap->sys_ptr);
pExaPixmap->sys_ptr = NULL;
pExaPixmap->pDamage = NULL;
}
......
......@@ -2431,8 +2431,7 @@ int __glXDisp_ClientInfo(__GLXclientState *cl, GLbyte *pc)
cl->GLClientmajorVersion = req->major;
cl->GLClientminorVersion = req->minor;
if (cl->GLClientextensions)
free(cl->GLClientextensions);
free(cl->GLClientextensions);
buf = (const char *)(req+1);
cl->GLClientextensions = xstrdup(buf);
......
......@@ -205,8 +205,8 @@ GLboolean __glXFreeContext(__GLXcontext *cx)
{
if (cx->idExists || cx->isCurrent) return GL_FALSE;
if (cx->feedbackBuf) free(cx->feedbackBuf);
if (cx->selectBuf) free(cx->selectBuf);
free(cx->feedbackBuf);
free(cx->selectBuf);
if (cx == __glXLastContext) {
__glXFlushContextCache();
}
......@@ -323,10 +323,10 @@ glxClientCallback (CallbackListPtr *list,
}
}
if (cl->returnBuf) free(cl->returnBuf);
if (cl->largeCmdBuf) free(cl->largeCmdBuf);
if (cl->currentContexts) free(cl->currentContexts);
if (cl->GLClientextensions) free(cl->GLClientextensions);
free(cl->returnBuf);
free(cl->largeCmdBuf);
free(cl->currentContexts);
free(cl->GLClientextensions);
break;
default:
......
......@@ -272,10 +272,8 @@ char *__glXcombine_strings(const char *cext_string, const char *sext_string)
s2 = sext_string;
}
if (!combo_string || !s1) {
if (combo_string)
free(combo_string);
if (s1)
free(s1);
free(combo_string);
free(s1);
return NULL;
}
combo_string[0] = '\0';
......
......@@ -97,9 +97,7 @@ static int __glXMakeBitmapFromGlyph(FontPtr font, CharInfoPtr pci)
pci->metrics.characterWidth, 0,
allocbuf ? allocbuf : buf) );
if (allocbuf) {
free(allocbuf);
}
free(allocbuf);
return Success;
#undef __GL_CHAR_BUF_SIZE
}
......
......@@ -98,7 +98,7 @@ const char *dmxConfigCopyString(const char *string, int length)
void dmxConfigFree(void *area)
{
if (area) free(area);
free(area);
}
DMXConfigTokenPtr dmxConfigCreateToken(int token, int line,
......@@ -370,7 +370,7 @@ DMXConfigOptionPtr dmxConfigCreateOption(DMXConfigTokenPtr pStart,
void dmxConfigFreeOption(DMXConfigOptionPtr p)
{
if (!p) return;
if (p->string) free(p->string);
free(p->string);
dmxConfigFreeToken(p->start);
dmxConfigFreeString(p->option);
dmxConfigFreeToken(p->end);
......
......@@ -351,7 +351,7 @@ do { \
#define MAXSCREENSFREE(o) \
do { \
if (o) free(o); \
free(o); \
o = NULL; \
} while (0)
......
......@@ -606,8 +606,8 @@ void InitOutput(ScreenInfo *pScreenInfo, int argc, char *argv[])
dmxScreens[i].stat = NULL;
}
for (i = 0; i < dmxNumInputs; i++) dmxInputFree(&dmxInputs[i]);
if (dmxScreens) free(dmxScreens);
if (dmxInputs) free(dmxInputs);
free(dmxScreens);
free(dmxInputs);
dmxScreens = NULL;
dmxInputs = NULL;
dmxNumScreens = 0;
......
......@@ -122,7 +122,7 @@ DMXStatInfo *dmxStatAlloc(void)
/** Free the memory used by a \a DMXStatInfo structure. */
void dmxStatFree(DMXStatInfo *pt)
{
if (pt) free(pt);
free(pt);
}
static void dmxStatValue(DMXStatAvg *data, unsigned long value)
......
......@@ -105,7 +105,5 @@ __glXRealloc(void *addr, size_t newSize)
void
__glXFree(void *addr)
{
if (addr) {
free(addr);
}
free(addr);
}
......@@ -531,8 +531,7 @@ Bool glxInitVisuals(int *nvisualp, VisualPtr *visualp,
__glXFree(pNewVisualConfigs);
/* Free the private list created by DDX HW driver */
if (visualPrivates)
free(visualPrivates);
free(visualPrivates);
visualPrivates = NULL;
return TRUE;
......
......@@ -114,7 +114,7 @@ pointer dmxBackendCreatePrivate(DeviceIntPtr pDevice)
* #dmxBackendCreatePrivate. */
void dmxBackendDestroyPrivate(pointer private)
{
if (private) free(private);
free(private);
}
static void *dmxBackendTestScreen(DMXScreenInfo *dmxScreen, void *closure)
......
......@@ -148,7 +148,7 @@ pointer dmxConsoleCreatePrivate(DeviceIntPtr pDevice)
/** If \a private is non-NULL, free its associated memory. */
void dmxConsoleDestroyPrivate(pointer private)
{
if (private) free(private);
free(private);
}
static void dmxConsoleDrawFineCursor(myPrivate *priv, XRectangle *rect)
......
......@@ -1084,9 +1084,9 @@ static void dmxInputFreeLocal(DMXLocalInputInfoRec *local)
if (local->isCore && local->type == DMX_LOCAL_KEYBOARD)
dmxLocalCoreKeyboard = NULL;
if (local->destroy_private) local->destroy_private(local->private);
if (local->history) free(local->history);
if (local->valuators) free(local->valuators);
if (local->deviceName) free(local->deviceName);
free(local->history);
free(local->valuators);
free(local->deviceName);
local->private = NULL;
local->history = NULL;
local->deviceName = NULL;
......@@ -1100,9 +1100,9 @@ void dmxInputFree(DMXInputInfo *dmxInput)
if (!dmxInput) return;
if (dmxInput->keycodes) free(dmxInput->keycodes);
if (dmxInput->symbols) free(dmxInput->symbols);
if (dmxInput->geometry) free(dmxInput->geometry);
free(dmxInput->keycodes);
free(dmxInput->symbols);
free(dmxInput->geometry);
for (i = 0; i < dmxInput->numDevs; i++) {
dmxInputFreeLocal(dmxInput->devs[i]);
......
......@@ -368,7 +368,7 @@ pointer kbdLinuxCreatePrivate(DeviceIntPtr pKeyboard)
/** Destroy a private structure. */
void kbdLinuxDestroyPrivate(pointer priv)
{
if (priv) free(priv);
free(priv);
}
/** Ring the bell.
......
......@@ -301,7 +301,7 @@ pointer msLinuxCreatePrivate(DeviceIntPtr pMouse)
/** Destroy a private structure. */
void msLinuxDestroyPrivate(pointer priv)
{
if (priv) free(priv);
free(priv);
}
/** Fill the \a info structure with information needed to initialize \a
......
......@@ -269,7 +269,7 @@ pointer ps2LinuxCreatePrivate(DeviceIntPtr pMouse)
/** Destroy a private structure. */
void ps2LinuxDestroyPrivate(pointer priv)
{
if (priv) free(priv);
free(priv);
}
/** Fill the \a info structure with information needed to initialize \a
......
......@@ -377,5 +377,5 @@ pointer usbCreatePrivate(DeviceIntPtr pDevice)
/** Destroy a private structure. */
void usbDestroyPrivate(pointer priv)
{
if (priv) free(priv);
free(priv);
}
......@@ -168,8 +168,7 @@ fakeMapFramebuffer (KdScreenInfo *screen)
KdSetPointerMatrix (&m);
priv->bytes_per_line = ((screen->width * screen->fb.bitsPerPixel + 31) >> 5) << 2;
if (priv->base)
free (priv->base);
free(priv->base);
priv->base = malloc (priv->bytes_per_line * screen->height);
if (scrpriv->shadow)
......
......@@ -120,8 +120,7 @@ FreeList(const char ***list, int *lines)
int i;
for (i = 0; i < *lines; i++) {
if ((*list)[i])
free((*list)[i]);
free((*list)[i]);
}
free(*list);
*list = NULL;
......
......@@ -848,10 +848,10 @@ xf86ReconfigureLayout(void)
for (i = 0; i < MAXSCREENS; i++) {