[PATCH] xf86-video-mga: remove redundant NULL checks for free()
Nicolas Kaiser
nikai at nikai.net
Sun Apr 3 16:31:50 PDT 2011
free() can handle NULL.
Signed-off-by: Nicolas Kaiser <nikai at nikai.net>
---
* Cyril Brulebois <kibi at debian.org>:
> Nicolas Kaiser <nikai at nikai.net> (02/04/2011):
> > - if (pptNew2) xfree(pptNew2);
> > - if (pboxNew2) xfree(pboxNew2);
> > + if (pptNew2) free(pptNew2);
> > + if (pboxNew2) free(pboxNew2);
>
> and others, you may want to get rid of the if(), free() can handle
> NULL.
Sounds good to me. This patch applies on top of
"xf86-video-mga: replace deprecated X*alloc functions".
Best regards,
Nicolas Kaiser
src/mga_dri.c | 42 +++++++++++----------------------
src/mga_driver.c | 68 +++++++++++++++++------------------------------------
src/mga_merge.c | 6 +---
src/mga_video.c | 3 +-
4 files changed, 39 insertions(+), 80 deletions(-)
diff --git a/src/mga_dri.c b/src/mga_dri.c
index 8b1d751..7387f2d 100644
--- a/src/mga_dri.c
+++ b/src/mga_dri.c
@@ -1012,12 +1012,10 @@ static void MGADRIMoveBuffersXAA(WindowPtr pParent, DDXPointRec ptOldOrg,
pboxNew2 = (BoxPtr)malloc(sizeof(BoxRec)*nbox);
pptNew2 = (DDXPointPtr)malloc(sizeof(DDXPointRec)*nbox);
if (!pboxNew2 || !pptNew2) {
- if (pptNew2) free(pptNew2);
- if (pboxNew2) free(pboxNew2);
- if (pboxNew1) {
- free(pptNew1);
- free(pboxNew1);
- }
+ free(pptNew2);
+ free(pboxNew2);
+ free(pptNew1);
+ free(pboxNew1);
return;
}
pboxBase = pboxNext = pbox;
@@ -1066,14 +1064,10 @@ static void MGADRIMoveBuffersXAA(WindowPtr pParent, DDXPointRec ptOldOrg,
}
MGASelectBuffer(pScrn, MGA_FRONT);
- if (pboxNew2) {
- free(pptNew2);
- free(pboxNew2);
- }
- if (pboxNew1) {
- free(pptNew1);
- free(pboxNew1);
- }
+ free(pptNew2);
+ free(pboxNew2);
+ free(pptNew1);
+ free(pboxNew1);
pMga->AccelInfoRec->NeedToSync = TRUE;
@@ -1495,21 +1489,13 @@ void MGADRICloseScreen( ScreenPtr pScreen )
DRICloseScreen( pScreen );
if ( pMga->pDRIInfo ) {
- if ( pMga->pDRIInfo->devPrivate ) {
- free( pMga->pDRIInfo->devPrivate );
- pMga->pDRIInfo->devPrivate = 0;
- }
+ free( pMga->pDRIInfo->devPrivate );
+ pMga->pDRIInfo->devPrivate = 0;
DRIDestroyInfoRec( pMga->pDRIInfo );
pMga->pDRIInfo = 0;
}
- if ( pMga->DRIServerInfo ) {
- free( pMga->DRIServerInfo );
- pMga->DRIServerInfo = 0;
- }
- if ( pMga->pVisualConfigs ) {
- free( pMga->pVisualConfigs );
- }
- if ( pMga->pVisualConfigsPriv ) {
- free( pMga->pVisualConfigsPriv );
- }
+ free( pMga->DRIServerInfo );
+ pMga->DRIServerInfo = 0;
+ free( pMga->pVisualConfigs );
+ free( pMga->pVisualConfigsPriv );
}
diff --git a/src/mga_driver.c b/src/mga_driver.c
index 01bec70..51e86da 100644
--- a/src/mga_driver.c
+++ b/src/mga_driver.c
@@ -644,8 +644,6 @@ MGAGetRec(ScrnInfoPtr pScrn)
void
MGAFreeRec(ScrnInfoPtr pScrn)
{
- if (pScrn->driverPrivate == NULL)
- return;
free(pScrn->driverPrivate);
pScrn->driverPrivate = NULL;
}
@@ -2490,8 +2488,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags)
pMga->FbMapSize,
LOOKUP_BEST_REFRESH);
- if (linePitches)
- free(linePitches);
+ free(linePitches);
}
if (i < 1 && pMga->FBDev) {
@@ -2804,27 +2801,19 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags)
/* Both boards have done there initialization */
MGACloseLibrary(pMga->pBoard);
- if (pMga->pBoard)
- free(pMga->pBoard);
- if (pMga->pClientStruct)
- free(pMga->pClientStruct);
- if (pMga->pMgaModeInfo)
- free(pMga->pMgaModeInfo);
- if (pMga->pMgaHwInfo)
- free(pMga->pMgaHwInfo);
+ free(pMga->pBoard);
+ free(pMga->pClientStruct);
+ free(pMga->pMgaModeInfo);
+ free(pMga->pMgaHwInfo);
pMgaEnt->refCount = 0;
}
} else {
MGACloseLibrary(pMga->pBoard);
- if (pMga->pBoard)
- free(pMga->pBoard);
- if (pMga->pClientStruct)
- free(pMga->pClientStruct);
- if (pMga->pMgaModeInfo)
- free(pMga->pMgaModeInfo);
- if (pMga->pMgaHwInfo)
- free(pMga->pMgaHwInfo);
+ free(pMga->pBoard);
+ free(pMga->pClientStruct);
+ free(pMga->pMgaModeInfo);
+ free(pMga->pMgaHwInfo);
}
); /* MGA_HAL */
@@ -4240,26 +4229,18 @@ MGACloseScreen(int scrnIndex, ScreenPtr pScreen)
/* Both boards have closed there screen */
MGACloseLibrary(pMga->pBoard);
- if (pMga->pBoard)
- free(pMga->pBoard);
- if (pMga->pClientStruct)
- free(pMga->pClientStruct);
- if (pMga->pMgaModeInfo)
- free(pMga->pMgaModeInfo);
- if (pMga->pMgaHwInfo)
- free(pMga->pMgaHwInfo);
+ free(pMga->pBoard);
+ free(pMga->pClientStruct);
+ free(pMga->pMgaModeInfo);
+ free(pMga->pMgaHwInfo);
}
} else {
MGACloseLibrary(pMga->pBoard);
- if (pMga->pBoard)
- free(pMga->pBoard);
- if (pMga->pClientStruct)
- free(pMga->pClientStruct);
- if (pMga->pMgaModeInfo)
- free(pMga->pMgaModeInfo);
- if (pMga->pMgaHwInfo)
- free(pMga->pMgaHwInfo);
+ free(pMga->pBoard);
+ free(pMga->pClientStruct);
+ free(pMga->pMgaModeInfo);
+ free(pMga->pMgaHwInfo);
}
); /* MGA_HAL */
#endif
@@ -4276,16 +4257,11 @@ MGACloseScreen(int scrnIndex, ScreenPtr pScreen)
#endif
if (pMga->CursorInfoRec)
xf86DestroyCursorInfoRec(pMga->CursorInfoRec);
- if (pMga->ShadowPtr)
- free(pMga->ShadowPtr);
- if (pMga->DGAModes)
- free(pMga->DGAModes);
- if (pMga->adaptor)
- free(pMga->adaptor);
- if (pMga->portPrivate)
- free(pMga->portPrivate);
- if (pMga->ScratchBuffer)
- free(pMga->ScratchBuffer);
+ free(pMga->ShadowPtr);
+ free(pMga->DGAModes);
+ free(pMga->adaptor);
+ free(pMga->portPrivate);
+ free(pMga->ScratchBuffer);
pScrn->vtSema = FALSE;
diff --git a/src/mga_merge.c b/src/mga_merge.c
index 7121d05..4c7d900 100644
--- a/src/mga_merge.c
+++ b/src/mga_merge.c
@@ -538,8 +538,7 @@ MGAPreInitMergedFB(ScrnInfoPtr pScrn1, int flags)
pMga->FbMapSize,
LOOKUP_BEST_REFRESH);
- if (linePitches)
- free(linePitches);
+ free(linePitches);
}
@@ -929,8 +928,7 @@ MGACloseScreenMerged(int scrnIndex, ScreenPtr pScreen) {
pScrn1->currentMode = pScrn1->modes;
do {
DisplayModePtr p = pScrn1->currentMode->next;
- if(pScrn1->currentMode->Private)
- free(pScrn1->currentMode->Private);
+ free(pScrn1->currentMode->Private);
free(pScrn1->currentMode);
pScrn1->currentMode = p;
}while( pScrn1->currentMode != pScrn1->modes);
diff --git a/src/mga_video.c b/src/mga_video.c
index d251370..3c21b45 100644
--- a/src/mga_video.c
+++ b/src/mga_video.c
@@ -146,8 +146,7 @@ void MGAInitVideo(ScreenPtr pScreen)
if(num_adaptors)
xf86XVScreenInit(pScreen, adaptors, num_adaptors);
- if(newAdaptors)
- free(newAdaptors);
+ free(newAdaptors);
}
/* client libraries expect an encoding */
--
1.7.3.4
More information about the xorg-devel
mailing list