Cleanup: Do not check pointers before deleting them, part 2.
authorLei Zhang <thestig@chromium.org>
Fri, 17 Jul 2015 01:28:49 +0000 (18:28 -0700)
committerLei Zhang <thestig@chromium.org>
Fri, 17 Jul 2015 01:28:49 +0000 (18:28 -0700)
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/1195363002 .

16 files changed:
core/src/fpdfapi/fpdf_render/fpdf_render.cpp
core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp
core/src/fxcodec/jbig2/JBig2_GeneralDecoder.cpp
core/src/fxge/agg/src/fx_agg_driver.cpp
core/src/fxge/android/fpf_skiamodule.cpp
core/src/fxge/apple/fx_mac_imp.cpp
core/src/fxge/win32/fx_win32_device.cpp
core/src/fxge/win32/fx_win32_dwrite.cpp
fpdfsdk/src/formfiller/FFL_ComboBox.cpp
fpdfsdk/src/formfiller/FFL_ListBox.cpp
fpdfsdk/src/formfiller/FFL_TextField.cpp
fpdfsdk/src/fpdf_transformpage.cpp
fpdfsdk/src/fpdftext.cpp
fpdfsdk/src/javascript/JS_Context.cpp
fpdfsdk/src/javascript/JS_Runtime.cpp
fpdfsdk/src/pdfwindow/PWL_FontMap.cpp

index c4a9d77..a894e84 100644 (file)
@@ -202,9 +202,7 @@ CPDF_RenderStatus::CPDF_RenderStatus()
 
 CPDF_RenderStatus::~CPDF_RenderStatus()
 {
-    if (m_pObjectRenderer) {
-        delete m_pObjectRenderer;
-    }
+    delete m_pObjectRenderer;
 }
 
 FX_BOOL CPDF_RenderStatus::Initialize(CPDF_RenderContext* pContext, CFX_RenderDevice* pDevice,
@@ -665,9 +663,7 @@ void CPDF_RenderStatus::ProcessClipPath(CPDF_ClipPath ClipPath, const CFX_Affine
             ProcessText(pText, pObj2Device, pTextClippingPath);
         }
     }
-    if (pTextClippingPath) {
-        delete pTextClippingPath;
-    }
+    delete pTextClippingPath;
 }
 void CPDF_RenderStatus::DrawClipPath(CPDF_ClipPath ClipPath, const CFX_AffineMatrix* pObj2Device)
 {
@@ -859,9 +855,7 @@ FX_BOOL CPDF_RenderStatus::ProcessTransparency(const CPDF_PageObject* pPageObj,
         Transparency |= PDFTRANS_GROUP;
     }
     CompositeDIBitmap(bitmap, rect.left, rect.top, 0, 255, blend_type, Transparency);
-    if (oriDevice) {
-        delete oriDevice;
-    }
+    delete oriDevice;
     return TRUE;
 }
 CFX_DIBitmap* CPDF_RenderStatus::GetBackdrop(const CPDF_PageObject* pObj, const FX_RECT& rect, int& left, int& top,
@@ -1271,9 +1265,7 @@ CPDF_DeviceBuffer::CPDF_DeviceBuffer()
 }
 CPDF_DeviceBuffer::~CPDF_DeviceBuffer()
 {
-    if (m_pBitmap) {
-        delete m_pBitmap;
-    }
+    delete m_pBitmap;
 }
 FX_BOOL CPDF_DeviceBuffer::Initialize(CPDF_RenderContext* pContext, CFX_RenderDevice* pDevice, FX_RECT* pRect,
                                       const CPDF_PageObject* pObj, int max_dpi)
@@ -1330,9 +1322,7 @@ CPDF_ScaledRenderBuffer::CPDF_ScaledRenderBuffer()
 }
 CPDF_ScaledRenderBuffer::~CPDF_ScaledRenderBuffer()
 {
-    if (m_pBitmapDevice) {
-        delete m_pBitmapDevice;
-    }
+    delete m_pBitmapDevice;
 }
 #define _FPDFAPI_IMAGESIZE_LIMIT_      (30 * 1024 * 1024)
 FX_BOOL CPDF_ScaledRenderBuffer::Initialize(CPDF_RenderContext* pContext, CFX_RenderDevice* pDevice, FX_RECT* pRect,
index f3f0375..0730206 100644 (file)
@@ -297,21 +297,13 @@ CPDF_ImageRenderer::CPDF_ImageRenderer()
 }
 CPDF_ImageRenderer::~CPDF_ImageRenderer()
 {
-    if (m_pQuickStretcher) {
-        delete m_pQuickStretcher;
-    }
-    if (m_pTransformer) {
-        delete m_pTransformer;
-    }
+    delete m_pQuickStretcher;
+    delete m_pTransformer;
     if (m_DeviceHandle) {
         m_pRenderStatus->m_pDevice->CancelDIBits(m_DeviceHandle);
     }
-    if (m_LoadHandle) {
-        delete (CPDF_ProgressiveImageLoaderHandle*)m_LoadHandle;
-    }
-    if (m_pClone) {
-        delete m_pClone;
-    }
+    delete (CPDF_ProgressiveImageLoaderHandle*)m_LoadHandle;
+    delete m_pClone;
 }
 FX_BOOL CPDF_ImageRenderer::StartLoadDIBSource()
 {
@@ -813,15 +805,11 @@ CPDF_QuickStretcher::CPDF_QuickStretcher()
 }
 CPDF_QuickStretcher::~CPDF_QuickStretcher()
 {
-    if (m_pBitmap) {
-        delete m_pBitmap;
-    }
+    delete m_pBitmap;
     if (m_pCS) {
         m_pCS->ReleaseCS();
     }
-    if (m_pDecoder) {
-        delete m_pDecoder;
-    }
+    delete m_pDecoder;
 }
 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(const uint8_t* src_buf, FX_DWORD src_size, int width, int height,
         int nComps, int bpc, const CPDF_Dictionary* pParams);
@@ -1085,9 +1073,7 @@ CFX_DIBitmap* CPDF_RenderStatus::LoadSMask(CPDF_Dictionary* pSMaskDict,
     } else {
         FXSYS_memcpy(dest_buf, src_buf, dest_pitch * height);
     }
-    if (pFunc) {
-        delete pFunc;
-    }
+    delete pFunc;
     FX_Free(pTransfer);
     return pMask;
 }
index 929180e..622f04b 100644 (file)
@@ -3027,9 +3027,7 @@ CJBig2_SymbolDict *CJBig2_SDDProc::decode_Huffman(CJBig2_BitStream *pStream,
     return pDict;
 failed:
     for(I = 0; I < NSYMSDECODED; I++) {
-        if (SDNEWSYMS[I]) {
-            delete SDNEWSYMS[I];
-        }
+        delete SDNEWSYMS[I];
     }
     m_pModule->JBig2_Free(SDNEWSYMS);
     if(SDREFAGG == 0) {
@@ -3094,15 +3092,11 @@ CJBig2_Image *CJBig2_HTRDProc::decode_Arith(CJBig2_ArithDecoder *pArithDecoder,
         }
     }
     m_pModule->JBig2_Free(GI);
-    if(HSKIP) {
-        delete HSKIP;
-    }
+    delete HSKIP;
     delete pGID;
     return HTREG;
 failed:
-    if(HSKIP) {
-        delete HSKIP;
-    }
+    delete HSKIP;
     delete pGID;
     delete HTREG;
     return NULL;
index 8e7846a..475e5f6 100644 (file)
@@ -207,9 +207,7 @@ CFX_AggDeviceDriver::~CFX_AggDeviceDriver()
 {
     delete m_pClipRgn;
     for (int i = 0; i < m_StateStack.GetSize(); i ++)
-        if (m_StateStack[i]) {
-            delete (CFX_ClipRgn*)m_StateStack[i];
-        }
+        delete (CFX_ClipRgn*)m_StateStack[i];
     DestroyPlatform();
 }
 #if _FXM_PLATFORM_  != _FXM_PLATFORM_APPLE_
index 37bfd9c..296073c 100644 (file)
@@ -22,10 +22,8 @@ CFPF_SkiaDeviceModule::~CFPF_SkiaDeviceModule()
 }
 void CFPF_SkiaDeviceModule::Destroy()
 {
-    if (gs_pPFModule) {
-        delete (CFPF_SkiaDeviceModule*)gs_pPFModule;
-        gs_pPFModule = NULL;
-    }
+    delete (CFPF_SkiaDeviceModule*)gs_pPFModule;
+    gs_pPFModule = NULL;
 }
 IFPF_FontMgr* CFPF_SkiaDeviceModule::GetFontMgr()
 {
index 3a9b9f9..04b04b8 100644 (file)
@@ -100,9 +100,7 @@ void CFX_GEModule::InitPlatform()
 }
 void CFX_GEModule::DestroyPlatform()
 {
-    if (m_pPlatformData) {
-        delete (CApplePlatform *) m_pPlatformData;
-    }
+    delete (CApplePlatform *)m_pPlatformData;
     m_pPlatformData = NULL;
 }
 #endif
index 899adf5..b0dbc14 100644 (file)
@@ -410,9 +410,7 @@ void CFX_GEModule::InitPlatform()
 }
 void CFX_GEModule::DestroyPlatform()
 {
-    if (m_pPlatformData) {
-        delete (CWin32Platform*)m_pPlatformData;
-    }
+    delete (CWin32Platform*)m_pPlatformData;
     m_pPlatformData = NULL;
 }
 CGdiDeviceDriver::CGdiDeviceDriver(HDC hDC, int device_class)
index 3cde3bf..889a568 100644 (file)
@@ -262,9 +262,7 @@ FX_BOOL     CDWriteExt::DwRendingString(void* renderTarget, CFX_ClipRgn* pClipRgn, F
 }
 void CDWriteExt::DwDeleteRenderingTarget(void* renderTarget)
 {
-    if (renderTarget) {
-        delete (CDwGdiTextRenderer*)renderTarget;
-    }
+    delete (CDwGdiTextRenderer*)renderTarget;
 }
 void CDWriteExt::DwDeleteFont(void* pFont)
 {
index 5618e8a..d3a4944 100644 (file)
@@ -23,11 +23,7 @@ CFFL_ComboBox::CFFL_ComboBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) :
 
 CFFL_ComboBox::~CFFL_ComboBox()
 {
-       if (m_pFontMap)
-       {
-               delete m_pFontMap;
-               m_pFontMap = NULL;
-       }
+    delete m_pFontMap;
 }
 
 PWL_CREATEPARAM CFFL_ComboBox::GetCreateParam()
index 28dcf34..c105cfc 100644 (file)
@@ -26,11 +26,7 @@ CFFL_ListBox::CFFL_ListBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) :
 
 CFFL_ListBox::~CFFL_ListBox()
 {
-       if (m_pFontMap)
-       {
-               delete m_pFontMap;
-               m_pFontMap = NULL;
-       }
+    delete m_pFontMap;
 }
 
 PWL_CREATEPARAM        CFFL_ListBox::GetCreateParam()
index ed155fb..a5be60e 100644 (file)
@@ -19,12 +19,7 @@ CFFL_TextField::CFFL_TextField(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot)
 
 CFFL_TextField::~CFFL_TextField()
 {
-       if (m_pFontMap)
-       {
-               delete m_pFontMap;
-               m_pFontMap = NULL;
-       }
-
+    delete m_pFontMap;
 }
 
 PWL_CREATEPARAM CFFL_TextField::GetCreateParam()
index dca0c23..5ede626 100644 (file)
@@ -211,8 +211,7 @@ DLLEXPORT FPDF_CLIPPATH STDCALL FPDF_CreateClipPath(float left, float bottom, fl
 
 DLLEXPORT void STDCALL FPDF_DestroyClipPath(FPDF_CLIPPATH clipPath)
 {
-       if(clipPath)
-               delete (CPDF_ClipPath*)clipPath;
+    delete (CPDF_ClipPath*)clipPath;
 }
 
 void OutputPath(CFX_ByteTextBuf& buf, CPDF_Path path)
index aba24f4..4a65715 100644 (file)
@@ -26,11 +26,7 @@ DLLEXPORT FPDF_TEXTPAGE STDCALL FPDFText_LoadPage(FPDF_PAGE page)
 }
 DLLEXPORT void STDCALL FPDFText_ClosePage(FPDF_TEXTPAGE text_page)
 {
-       if (text_page){
-               IPDF_TextPage* textpage=(IPDF_TextPage*)text_page;
-               delete textpage;
-               text_page=NULL;
-       }
+    delete (IPDF_TextPage*)text_page;
 }
 DLLEXPORT int STDCALL FPDFText_CountChars(FPDF_TEXTPAGE text_page)
 {
@@ -246,9 +242,6 @@ DLLEXPORT void STDCALL FPDFLink_GetRect(FPDF_PAGELINK link_page,int link_index,
 }
 DLLEXPORT void STDCALL FPDFLink_CloseWebLinks(FPDF_PAGELINK link_page)
 {
-       if (!link_page) return;
-       IPDF_LinkExtract* pageLink=(IPDF_LinkExtract*)link_page;
-       delete pageLink;
-       pageLink =NULL;
+    delete (IPDF_LinkExtract*)link_page;
 }
 
index 924ab1e..72be34d 100644 (file)
@@ -24,11 +24,7 @@ CJS_Context::CJS_Context(CJS_Runtime* pRuntime) :
 
 CJS_Context::~CJS_Context(void)
 {
-       if (m_pEventHandler)
-       {
-               delete m_pEventHandler;
-               m_pEventHandler = NULL;
-       }
+    delete m_pEventHandler;
 }
 
 CPDFSDK_Document* CJS_Context::GetReaderDocument()
index f21819a..2343eb3 100644 (file)
@@ -65,8 +65,7 @@ void                                                  CJS_RuntimeFactory::Release()
 
 void                                                   CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime)
 {
-       if(pRuntime)
-               delete (CJS_Runtime*)pRuntime;
+    delete (CJS_Runtime*)pRuntime;
 }
 
 CJS_GlobalData*        CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp)
index 8dff4ea..84b8c94 100644 (file)
@@ -21,13 +21,10 @@ CPWL_FontMap::CPWL_FontMap(IFX_SystemHandler* pSystemHandler) :
 
 CPWL_FontMap::~CPWL_FontMap()
 {
-       if (m_pPDFDoc)
-       {
-               delete m_pPDFDoc;
-               m_pPDFDoc = NULL;
-       }
+    delete m_pPDFDoc;
+    m_pPDFDoc = NULL;
 
-       Empty();
+    Empty();
 }
 
 void CPWL_FontMap::SetSystemHandler(IFX_SystemHandler* pSystemHandler)