Changeset 73250 in webkit
- Timestamp:
- Dec 3, 2010 12:53:41 AM (13 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r73249 r73250 1 2010-12-03 Noel Gordon <noel.gordon@gmail.com> 2 3 Reviewed by Darin Fisher. 4 5 [chromium] PNG encoder leaks memory on png_write_row errors. 6 https://bugs.webkit.org/show_bug.cgi?id=50439 7 8 Move the creation of needed C++ objects before the setjmp() point so 9 those objects have their destructors called if libpng errors invoke 10 the setjmp() return path. 11 12 Other minor cleanup: use the skia bitmap locker class, and remove the 13 PNGDestroyer class - instead directly call png_destroy_write_struct() 14 at each of the encodeImpl() return points. 15 16 No change in behaviour, so no new tests. 17 18 * platform/image-encoders/skia/PNGImageEncoder.cpp: 19 (WebCore::encodeImpl): 20 (WebCore::PNGImageEncoder::encode): 21 1 22 2010-12-02 Philippe Normand <pnormand@igalia.com> 2 23 -
trunk/WebCore/platform/image-encoders/skia/PNGImageEncoder.cpp
r73233 r73250 84 84 } 85 85 86 // Automatically destroys the given write structs on destruction to make87 // cleanup and error handling code cleaner.88 class PNGWriteStructDestroyer {89 public:90 PNGWriteStructDestroyer(png_struct** ps, png_info** pi)91 : m_pngStruct(ps)92 , m_pngInfo(pi) {93 }94 95 ~PNGWriteStructDestroyer() {96 png_destroy_write_struct(m_pngStruct, m_pngInfo);97 }98 99 private:100 png_struct** m_pngStruct;101 png_info** m_pngInfo;102 };103 104 86 static bool encodeImpl(const unsigned char* input, 105 87 const IntSize& size, … … 128 110 return false; 129 111 } 130 PNGWriteStructDestroyer destroyer(&pngPtr, &infoPtr); 112 113 OwnArrayPtr<unsigned char> rowPixels(new unsigned char[imageSize.width() * outputColorComponents]); 114 PNGEncoderState state(output); 131 115 132 116 if (setjmp(png_jmpbuf(pngPtr))) { 133 // The destroyer will ensure that the structures are cleaned up in this 134 // case, even though we may get here as a jump from random parts of the 135 // PNG library called below. 117 png_destroy_write_struct(&pngPtr, &infoPtr); 136 118 return false; 137 119 } 138 120 139 121 // Set our callback for libpng to give us the data. 140 PNGEncoderState state(output);141 122 png_set_write_fn(pngPtr, &state, encoderWriteCallback, NULL); 142 123 … … 146 127 png_write_info(pngPtr, infoPtr); 147 128 148 OwnArrayPtr<unsigned char> rowPixels(new unsigned char[imageSize.width() * outputColorComponents]);149 129 for (int y = 0; y < imageSize.height(); ++y) { 150 130 preMultipliedBGRAtoRGBA(&input[y * bytesPerRow], imageSize.width(), rowPixels.get()); … … 153 133 154 134 png_write_end(pngPtr, infoPtr); 135 png_destroy_write_struct(&pngPtr, &infoPtr); 155 136 return true; 156 137 } … … 162 143 return false; // Only support ARGB 32 bpp skia bitmaps. 163 144 164 image.lockPixels(); 165 bool result = encodeImpl(static_cast<unsigned char*>(image.getPixels()), IntSize(image.width(), image.height()), image.rowBytes(), output); 166 image.unlockPixels(); 167 return result; 145 SkAutoLockPixels bitmapLock(image); 146 return encodeImpl(static_cast<unsigned char*>(image.getPixels()), IntSize(image.width(), image.height()), image.rowBytes(), output); 168 147 } 169 148
Note: See TracChangeset
for help on using the changeset viewer.