From 60406bca86bce05065b961cb6cd09348c77be949 Mon Sep 17 00:00:00 2001 From: "mark@chromium.org" Date: Mon, 15 Jun 2009 23:49:18 +0000 Subject: Stop leaking CGBitmapContextRefs. Regression from r18363. BUG=14105 TEST=sh tools/valgrind/chrome_tests.sh --build_dir xcodebuild/Debug --test unit --gtest_filter=RenderWidgetHostTest.Resize Review URL: http://codereview.chromium.org/126159 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18452 0039d316-1c4b-4281-b951-d872f2087c98 --- skia/ext/bitmap_platform_device_mac.cc | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/skia/ext/bitmap_platform_device_mac.cc b/skia/ext/bitmap_platform_device_mac.cc index 834655d..fd8a3a8 100644 --- a/skia/ext/bitmap_platform_device_mac.cc +++ b/skia/ext/bitmap_platform_device_mac.cc @@ -209,10 +209,17 @@ BitmapPlatformDevice* BitmapPlatformDevice::Create(CGContextRef context, if (!context) context = CGContextForData(data, width, height); + else + CGContextRetain(context); - // The device object will take ownership of the graphics context. - return new BitmapPlatformDevice( + BitmapPlatformDevice* rv = new BitmapPlatformDevice( new BitmapPlatformDeviceData(context), bitmap); + + // The device object took ownership of the graphics context with its own + // CGContextRetain call. + CGContextRelease(context); + + return rv; } BitmapPlatformDevice* BitmapPlatformDevice::CreateWithData(uint8_t* data, @@ -223,7 +230,14 @@ BitmapPlatformDevice* BitmapPlatformDevice::CreateWithData(uint8_t* data, if (data) context = CGContextForData(data, width, height); - return Create(context, width, height, is_opaque); + BitmapPlatformDevice* rv = Create(context, width, height, is_opaque); + + // The device object took ownership of the graphics context with its own + // CGContextRetain call. + if (context) + CGContextRelease(context); + + return rv; } // The device will own the bitmap, which corresponds to also owning the pixel -- cgit v1.1