Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: core/src/fxge/dib/fx_dib_main.cpp

Issue 1192743004: Cleanup: Do not check pointers before deleting them. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxge/dib/fx_dib_engine.cpp ('k') | core/src/fxge/ge/fx_ge.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../../include/fxge/fx_dib.h" 7 #include "../../../include/fxge/fx_dib.h"
8 #include "../../../include/fxge/fx_ge.h" 8 #include "../../../include/fxge/fx_ge.h"
9 #include "../../../include/fxcodec/fx_codec.h" 9 #include "../../../include/fxcodec/fx_codec.h"
10 #include "dib_int.h" 10 #include "dib_int.h"
(...skipping 30 matching lines...) Expand all
41 m_Width = m_Height = 0; 41 m_Width = m_Height = 0;
42 m_Pitch = 0; 42 m_Pitch = 0;
43 m_pPalette = NULL; 43 m_pPalette = NULL;
44 m_pAlphaMask = NULL; 44 m_pAlphaMask = NULL;
45 } 45 }
46 CFX_DIBSource::~CFX_DIBSource() 46 CFX_DIBSource::~CFX_DIBSource()
47 { 47 {
48 if (m_pPalette) { 48 if (m_pPalette) {
49 FX_Free(m_pPalette); 49 FX_Free(m_pPalette);
50 } 50 }
51 if (m_pAlphaMask) { 51 delete m_pAlphaMask;
52 delete m_pAlphaMask;
53 }
54 } 52 }
55 CFX_DIBitmap::CFX_DIBitmap() 53 CFX_DIBitmap::CFX_DIBitmap()
56 { 54 {
57 m_bExtBuf = FALSE; 55 m_bExtBuf = FALSE;
58 m_pBuffer = NULL; 56 m_pBuffer = NULL;
59 m_pPalette = NULL; 57 m_pPalette = NULL;
60 } 58 }
61 #define _MAX_OOM_LIMIT_ 12000000 59 #define _MAX_OOM_LIMIT_ 12000000
62 FX_BOOL CFX_DIBitmap::Create(int width, int height, FXDIB_Format format, uint8_t * pBuffer, int pitch) 60 FX_BOOL CFX_DIBitmap::Create(int width, int height, FXDIB_Format format, uint8_t * pBuffer, int pitch)
63 { 61 {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 m_pBuffer = NULL; 130 m_pBuffer = NULL;
133 } 131 }
134 void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap) 132 void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap)
135 { 133 {
136 if (m_pBuffer && !m_bExtBuf) { 134 if (m_pBuffer && !m_bExtBuf) {
137 FX_Free(m_pBuffer); 135 FX_Free(m_pBuffer);
138 } 136 }
139 if (m_pPalette) { 137 if (m_pPalette) {
140 FX_Free(m_pPalette); 138 FX_Free(m_pPalette);
141 } 139 }
142 if (m_pAlphaMask) { 140 delete m_pAlphaMask;
143 delete m_pAlphaMask;
144 }
145 m_pBuffer = pSrcBitmap->m_pBuffer; 141 m_pBuffer = pSrcBitmap->m_pBuffer;
146 m_pPalette = pSrcBitmap->m_pPalette; 142 m_pPalette = pSrcBitmap->m_pPalette;
147 m_pAlphaMask = pSrcBitmap->m_pAlphaMask; 143 m_pAlphaMask = pSrcBitmap->m_pAlphaMask;
148 pSrcBitmap->m_pBuffer = NULL; 144 pSrcBitmap->m_pBuffer = NULL;
149 pSrcBitmap->m_pPalette = NULL; 145 pSrcBitmap->m_pPalette = NULL;
150 pSrcBitmap->m_pAlphaMask = NULL; 146 pSrcBitmap->m_pAlphaMask = NULL;
151 m_bpp = pSrcBitmap->m_bpp; 147 m_bpp = pSrcBitmap->m_bpp;
152 m_bExtBuf = pSrcBitmap->m_bExtBuf; 148 m_bExtBuf = pSrcBitmap->m_bExtBuf;
153 m_AlphaFlag = pSrcBitmap->m_AlphaFlag; 149 m_AlphaFlag = pSrcBitmap->m_AlphaFlag;
154 m_Width = pSrcBitmap->m_Width; 150 m_Width = pSrcBitmap->m_Width;
(...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 delete m_pBitmap; 1459 delete m_pBitmap;
1464 m_pBitmap = NULL; 1460 m_pBitmap = NULL;
1465 return; 1461 return;
1466 } 1462 }
1467 m_pBitmap->CopyPalette(pSrc->GetPalette()); 1463 m_pBitmap->CopyPalette(pSrc->GetPalette());
1468 m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask); 1464 m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask);
1469 } 1465 }
1470 } 1466 }
1471 CFX_DIBExtractor::~CFX_DIBExtractor() 1467 CFX_DIBExtractor::~CFX_DIBExtractor()
1472 { 1468 {
1473 if (m_pBitmap) { 1469 delete m_pBitmap;
1474 delete m_pBitmap;
1475 }
1476 } 1470 }
1477 CFX_FilteredDIB::CFX_FilteredDIB() 1471 CFX_FilteredDIB::CFX_FilteredDIB()
1478 { 1472 {
1479 m_pScanline = NULL; 1473 m_pScanline = NULL;
1480 m_pSrc = NULL; 1474 m_pSrc = NULL;
1481 } 1475 }
1482 CFX_FilteredDIB::~CFX_FilteredDIB() 1476 CFX_FilteredDIB::~CFX_FilteredDIB()
1483 { 1477 {
1484 if (m_pSrc && m_bAutoDropSrc) { 1478 if (m_bAutoDropSrc) {
1485 delete m_pSrc; 1479 delete m_pSrc;
1486 } 1480 }
1487 if (m_pScanline) { 1481 if (m_pScanline) {
1488 FX_Free(m_pScanline); 1482 FX_Free(m_pScanline);
1489 } 1483 }
1490 } 1484 }
1491 void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc) 1485 void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc)
1492 { 1486 {
1493 m_pSrc = pSrc; 1487 m_pSrc = pSrc;
1494 m_bAutoDropSrc = bAutoDropSrc; 1488 m_bAutoDropSrc = bAutoDropSrc;
(...skipping 19 matching lines...) Expand all
1514 } 1508 }
1515 CFX_ImageRenderer::CFX_ImageRenderer() 1509 CFX_ImageRenderer::CFX_ImageRenderer()
1516 { 1510 {
1517 m_Status = 0; 1511 m_Status = 0;
1518 m_pTransformer = NULL; 1512 m_pTransformer = NULL;
1519 m_bRgbByteOrder = FALSE; 1513 m_bRgbByteOrder = FALSE;
1520 m_BlendType = FXDIB_BLEND_NORMAL; 1514 m_BlendType = FXDIB_BLEND_NORMAL;
1521 } 1515 }
1522 CFX_ImageRenderer::~CFX_ImageRenderer() 1516 CFX_ImageRenderer::~CFX_ImageRenderer()
1523 { 1517 {
1524 if (m_pTransformer) { 1518 delete m_pTransformer;
1525 delete m_pTransformer;
1526 }
1527 } 1519 }
1528 extern FX_RECT _FXDIB_SwapClipBox(FX_RECT& clip, int width, int height, FX_BOOL bFlipX, FX_BOOL bFlipY); 1520 extern FX_RECT _FXDIB_SwapClipBox(FX_RECT& clip, int width, int height, FX_BOOL bFlipX, FX_BOOL bFlipY);
1529 FX_BOOL CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice, const CFX_ClipRgn* pClip Rgn, 1521 FX_BOOL CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice, const CFX_ClipRgn* pClip Rgn,
1530 const CFX_DIBSource* pSource, int bitmap_alpha, 1522 const CFX_DIBSource* pSource, int bitmap_alpha,
1531 FX_DWORD mask_color, const CFX_AffineMatrix* pM atrix, 1523 FX_DWORD mask_color, const CFX_AffineMatrix* pM atrix,
1532 FX_DWORD dib_flags, FX_BOOL bRgbByteOrder, 1524 FX_DWORD dib_flags, FX_BOOL bRgbByteOrder,
1533 int alpha_flag, void* pIccTransform, int blend_ type) 1525 int alpha_flag, void* pIccTransform, int blend_ type)
1534 { 1526 {
1535 m_Matrix = *pMatrix; 1527 m_Matrix = *pMatrix;
1536 CFX_FloatRect image_rect_f = m_Matrix.GetUnitRect(); 1528 CFX_FloatRect image_rect_f = m_Matrix.GetUnitRect();
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 return FALSE; 1622 return FALSE;
1631 } 1623 }
1632 return FALSE; 1624 return FALSE;
1633 } 1625 }
1634 CFX_BitmapStorer::CFX_BitmapStorer() 1626 CFX_BitmapStorer::CFX_BitmapStorer()
1635 { 1627 {
1636 m_pBitmap = NULL; 1628 m_pBitmap = NULL;
1637 } 1629 }
1638 CFX_BitmapStorer::~CFX_BitmapStorer() 1630 CFX_BitmapStorer::~CFX_BitmapStorer()
1639 { 1631 {
1640 if (m_pBitmap) { 1632 delete m_pBitmap;
1641 delete m_pBitmap;
1642 }
1643 } 1633 }
1644 CFX_DIBitmap* CFX_BitmapStorer::Detach() 1634 CFX_DIBitmap* CFX_BitmapStorer::Detach()
1645 { 1635 {
1646 CFX_DIBitmap* pBitmap = m_pBitmap; 1636 CFX_DIBitmap* pBitmap = m_pBitmap;
1647 m_pBitmap = NULL; 1637 m_pBitmap = NULL;
1648 return pBitmap; 1638 return pBitmap;
1649 } 1639 }
1650 void CFX_BitmapStorer::Replace(CFX_DIBitmap* pBitmap) 1640 void CFX_BitmapStorer::Replace(CFX_DIBitmap* pBitmap)
1651 { 1641 {
1652 if (m_pBitmap) { 1642 delete m_pBitmap;
1653 delete m_pBitmap;
1654 }
1655 m_pBitmap = pBitmap; 1643 m_pBitmap = pBitmap;
1656 } 1644 }
1657 void CFX_BitmapStorer::ComposeScanline(int line, const uint8_t* scanline, const uint8_t* scan_extra_alpha) 1645 void CFX_BitmapStorer::ComposeScanline(int line, const uint8_t* scanline, const uint8_t* scan_extra_alpha)
1658 { 1646 {
1659 uint8_t* dest_buf = (uint8_t*)m_pBitmap->GetScanline(line); 1647 uint8_t* dest_buf = (uint8_t*)m_pBitmap->GetScanline(line);
1660 uint8_t* dest_alpha_buf = m_pBitmap->m_pAlphaMask ? 1648 uint8_t* dest_alpha_buf = m_pBitmap->m_pAlphaMask ?
1661 (uint8_t*)m_pBitmap->m_pAlphaMask->GetScanline(li ne) : NULL; 1649 (uint8_t*)m_pBitmap->m_pAlphaMask->GetScanline(li ne) : NULL;
1662 if (dest_buf) { 1650 if (dest_buf) {
1663 FXSYS_memcpy(dest_buf, scanline, m_pBitmap->GetPitch()); 1651 FXSYS_memcpy(dest_buf, scanline, m_pBitmap->GetPitch());
1664 } 1652 }
1665 if (dest_alpha_buf) { 1653 if (dest_alpha_buf) {
1666 FXSYS_memcpy(dest_alpha_buf, scan_extra_alpha, m_pBitmap->m_pAlphaMask-> GetPitch()); 1654 FXSYS_memcpy(dest_alpha_buf, scan_extra_alpha, m_pBitmap->m_pAlphaMask-> GetPitch());
1667 } 1655 }
1668 } 1656 }
1669 FX_BOOL CFX_BitmapStorer::SetInfo(int width, int height, FXDIB_Format src_format , FX_DWORD* pSrcPalette) 1657 FX_BOOL CFX_BitmapStorer::SetInfo(int width, int height, FXDIB_Format src_format , FX_DWORD* pSrcPalette)
1670 { 1658 {
1671 m_pBitmap = new CFX_DIBitmap; 1659 m_pBitmap = new CFX_DIBitmap;
1672 if (!m_pBitmap->Create(width, height, src_format)) { 1660 if (!m_pBitmap->Create(width, height, src_format)) {
1673 delete m_pBitmap; 1661 delete m_pBitmap;
1674 m_pBitmap = NULL; 1662 m_pBitmap = NULL;
1675 return FALSE; 1663 return FALSE;
1676 } 1664 }
1677 if (pSrcPalette) { 1665 if (pSrcPalette) {
1678 m_pBitmap->CopyPalette(pSrcPalette); 1666 m_pBitmap->CopyPalette(pSrcPalette);
1679 } 1667 }
1680 return TRUE; 1668 return TRUE;
1681 } 1669 }
OLDNEW
« no previous file with comments | « core/src/fxge/dib/fx_dib_engine.cpp ('k') | core/src/fxge/ge/fx_ge.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698