Changeset 73250 in webkit


Ignore:
Timestamp:
Dec 3, 2010 12:53:41 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2010-12-03 Noel Gordon <noel.gordon@gmail.com>

Reviewed by Darin Fisher.

[chromium] PNG encoder leaks memory on png_write_row errors.
https://bugs.webkit.org/show_bug.cgi?id=50439

Move the creation of needed C++ objects before the setjmp() point so
those objects have their destructors called if libpng errors invoke
the setjmp() return path.

Other minor cleanup: use the skia bitmap locker class, and remove the
PNGDestroyer class - instead directly call png_destroy_write_struct()
at each of the encodeImpl() return points.

No change in behaviour, so no new tests.

  • platform/image-encoders/skia/PNGImageEncoder.cpp: (WebCore::encodeImpl): (WebCore::PNGImageEncoder::encode):
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r73249 r73250  
     12010-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
    1222010-12-02  Philippe Normand  <pnormand@igalia.com>
    223
  • trunk/WebCore/platform/image-encoders/skia/PNGImageEncoder.cpp

    r73233 r73250  
    8484}
    8585
    86 // Automatically destroys the given write structs on destruction to make
    87 // 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 
    10486static bool encodeImpl(const unsigned char* input,
    10587                       const IntSize& size,
     
    128110        return false;
    129111    }
    130     PNGWriteStructDestroyer destroyer(&pngPtr, &infoPtr);
     112
     113    OwnArrayPtr<unsigned char> rowPixels(new unsigned char[imageSize.width() * outputColorComponents]);
     114    PNGEncoderState state(output);
    131115
    132116    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);
    136118        return false;
    137119    }
    138120
    139121    // Set our callback for libpng to give us the data.
    140     PNGEncoderState state(output);
    141122    png_set_write_fn(pngPtr, &state, encoderWriteCallback, NULL);
    142123
     
    146127    png_write_info(pngPtr, infoPtr);
    147128
    148     OwnArrayPtr<unsigned char> rowPixels(new unsigned char[imageSize.width() * outputColorComponents]);
    149129    for (int y = 0; y < imageSize.height(); ++y) {
    150130        preMultipliedBGRAtoRGBA(&input[y * bytesPerRow], imageSize.width(), rowPixels.get());
     
    153133
    154134    png_write_end(pngPtr, infoPtr);
     135    png_destroy_write_struct(&pngPtr, &infoPtr);
    155136    return true;
    156137}
     
    162143        return false; // Only support ARGB 32 bpp skia bitmaps.
    163144
    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);
    168147}
    169148
Note: See TracChangeset for help on using the changeset viewer.