diff options
author | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-12 21:40:31 +0000 |
---|---|---|
committer | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-12 21:40:31 +0000 |
commit | 99432806a06b73301e4723de2d4b6b12aad63a21 (patch) | |
tree | e5a3acd4e58c9fae254f7b7ea496e4ce6e8fd0df /webkit | |
parent | efbb6048973339847cc5b8dbcd373702995b887a (diff) | |
download | chromium_src-99432806a06b73301e4723de2d4b6b12aad63a21.zip chromium_src-99432806a06b73301e4723de2d4b6b12aad63a21.tar.gz chromium_src-99432806a06b73301e4723de2d4b6b12aad63a21.tar.bz2 |
Coverity: Fix leaking NativeImageSkia in webkit_glue::DecodeImage.
CID=5406
BUG=none
TEST=tools/valgrind/chrome_tests.sh -t test_shell --gtest_filter=WebkitGlueTest.\*
Review URL: http://codereview.chromium.org/391026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31833 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/webkit_glue.cc | 30 | ||||
-rw-r--r-- | webkit/glue/webkit_glue_unittest.cc | 37 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.gyp | 3 |
3 files changed, 57 insertions, 13 deletions
diff --git a/webkit/glue/webkit_glue.cc b/webkit/glue/webkit_glue.cc index 85b72b16..a28446d 100644 --- a/webkit/glue/webkit_glue.cc +++ b/webkit/glue/webkit_glue.cc @@ -37,8 +37,14 @@ #include "base/sys_string_conversions.h" #include "net/base/escape.h" #include "skia/ext/platform_canvas.h" +#if defined(OS_MACOSX) +#include "skia/ext/skia_utils_mac.h" +#endif #include "third_party/skia/include/core/SkBitmap.h" +#include "third_party/WebKit/WebKit/chromium/public/WebData.h" #include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h" +#include "third_party/WebKit/WebKit/chromium/public/WebImage.h" +#include "third_party/WebKit/WebKit/chromium/public/WebSize.h" #include "third_party/WebKit/WebKit/chromium/public/WebString.h" #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" #if defined(OS_WIN) @@ -283,18 +289,18 @@ void CheckForLeaks() { } bool DecodeImage(const std::string& image_data, SkBitmap* image) { - RefPtr<WebCore::SharedBuffer> buffer( - WebCore::SharedBuffer::create(image_data.data(), - static_cast<int>(image_data.length()))); - WebCore::ImageSource image_source; - image_source.setData(buffer.get(), true); - - if (image_source.frameCount() > 0) { - *image = *reinterpret_cast<SkBitmap*>(image_source.createFrameAtIndex(0)); - return true; - } - // We failed to decode the image. - return false; + WebKit::WebData web_data(image_data.data(), image_data.length()); + WebKit::WebImage web_image(WebKit::WebImage::fromData(web_data, + WebKit::WebSize())); + if (web_image.isNull()) + return false; + +#if defined(OS_MACOSX) + *image = gfx::CGImageToSkBitmap(web_image.getCGImageRef()); +#else + *image = web_image.getSkBitmap(); +#endif + return true; } // NOTE: This pair of conversion functions are here instead of in glue_util.cc diff --git a/webkit/glue/webkit_glue_unittest.cc b/webkit/glue/webkit_glue_unittest.cc new file mode 100644 index 0000000..9ba56e3 --- /dev/null +++ b/webkit/glue/webkit_glue_unittest.cc @@ -0,0 +1,37 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "webkit/glue/webkit_glue.h" + +namespace { + +TEST(WebkitGlueTest, DecodeImageFail) { + std::string data("not an image"); + SkBitmap image; + EXPECT_FALSE(webkit_glue::DecodeImage(data, &image)); + EXPECT_TRUE(image.isNull()); +} + +TEST(WebkitGlueTest, DecodeImage) { + std::string data("GIF87a\x02\x00\x02\x00\xa1\x04\x00\x00\x00\x00\x00\x00\xff" + "\xff\x00\x00\x00\xff\x00,\x00\x00\x00\x00\x02\x00\x02\x00" + "\x00\x02\x03\x84\x16\x05\x00;", 42); + EXPECT_EQ(42u, data.size()); + SkBitmap image; + EXPECT_TRUE(webkit_glue::DecodeImage(data, &image)); + EXPECT_FALSE(image.isNull()); + EXPECT_EQ(2, image.width()); + EXPECT_EQ(2, image.height()); + EXPECT_EQ(SkBitmap::kARGB_8888_Config, image.config()); + image.lockPixels(); + EXPECT_EQ(SK_ColorBLACK, *image.getAddr32(0, 0)); + EXPECT_EQ(SK_ColorRED, *image.getAddr32(1, 0)); + EXPECT_EQ(SK_ColorGREEN, *image.getAddr32(0, 1)); + EXPECT_EQ(SK_ColorBLUE, *image.getAddr32(1, 1)); + image.unlockPixels(); +} + +} // namespace diff --git a/webkit/tools/test_shell/test_shell.gyp b/webkit/tools/test_shell/test_shell.gyp index 44a6ecb..313008a 100644 --- a/webkit/tools/test_shell/test_shell.gyp +++ b/webkit/tools/test_shell/test_shell.gyp @@ -398,10 +398,11 @@ '../../glue/resource_fetcher_unittest.cc', '../../glue/unittest_test_server.h', '../../glue/webcursor_unittest.cc', - '../../glue/webview_unittest.cc', '../../glue/webframe_unittest.cc', + '../../glue/webkit_glue_unittest.cc', '../../glue/webpasswordautocompletelistener_unittest.cc', '../../glue/webplugin_impl_unittest.cc', + '../../glue/webview_unittest.cc', '../webcore_unit_tests/BMPImageDecoder_unittest.cpp', '../webcore_unit_tests/GKURL_unittest.cpp', '../webcore_unit_tests/ICOImageDecoder_unittest.cpp', |