aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar msarett <msarett@google.com>2015-03-25 06:29:18 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-03-25 06:29:18 -0700
commitd0be5bb8994a081b44e06c75d07828214429b28d (patch)
tree046ac7fe2b3cb735e0b298064c84c7303ef365b2 /src
parent9bde918754bc292469d801f156f3b626eb3db780 (diff)
Fixing memory leak in ico decoder
BUG=skia: NOTREECHECKS=true TBR=scroggo@google.com NOTRY=true Review URL: https://codereview.chromium.org/1036873002
Diffstat (limited to 'src')
-rw-r--r--src/codec/SkCodec_libico.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/codec/SkCodec_libico.cpp b/src/codec/SkCodec_libico.cpp
index 2adfa9cfde..6a62ed8866 100644
--- a/src/codec/SkCodec_libico.cpp
+++ b/src/codec/SkCodec_libico.cpp
@@ -33,6 +33,9 @@ bool SkIcoCodec::IsIco(SkStream* stream) {
* Reads enough of the stream to determine the image format
*/
SkCodec* SkIcoCodec::NewFromStream(SkStream* stream) {
+ // Ensure that we do not leak the input stream
+ SkAutoTDelete<SkStream> inputStream(stream);
+
// Header size constants
static const uint32_t kIcoDirectoryBytes = 6;
static const uint32_t kIcoDirEntryBytes = 16;
@@ -40,7 +43,7 @@ SkCodec* SkIcoCodec::NewFromStream(SkStream* stream) {
// Read the directory header
SkAutoTDeleteArray<uint8_t> dirBuffer(
SkNEW_ARRAY(uint8_t, kIcoDirectoryBytes));
- if (stream->read(dirBuffer.get(), kIcoDirectoryBytes) !=
+ if (inputStream.get()->read(dirBuffer.get(), kIcoDirectoryBytes) !=
kIcoDirectoryBytes) {
SkDebugf("Error: unable to read ico directory header.\n");
return NULL;
@@ -56,7 +59,7 @@ SkCodec* SkIcoCodec::NewFromStream(SkStream* stream) {
// Ensure that we can read all of indicated directory entries
SkAutoTDeleteArray<uint8_t> entryBuffer(
SkNEW_ARRAY(uint8_t, numImages*kIcoDirEntryBytes));
- if (stream->read(entryBuffer.get(), numImages*kIcoDirEntryBytes) !=
+ if (inputStream.get()->read(entryBuffer.get(), numImages*kIcoDirEntryBytes) !=
numImages*kIcoDirEntryBytes) {
SkDebugf("Error: unable to read ico directory entries.\n");
return NULL;
@@ -121,14 +124,15 @@ SkCodec* SkIcoCodec::NewFromStream(SkStream* stream) {
// If we cannot skip, assume we have reached the end of the stream and
// stop trying to make codecs
- if (stream->skip(offset - bytesRead) != offset - bytesRead) {
+ if (inputStream.get()->skip(offset - bytesRead) != offset - bytesRead) {
SkDebugf("Warning: could not skip to ico offset.\n");
break;
}
bytesRead = offset;
// Create a new stream for the embedded codec
- SkAutoTUnref<SkData> data(SkData::NewFromStream(stream, size));
+ SkAutoTUnref<SkData> data(
+ SkData::NewFromStream(inputStream.get(), size));
if (NULL == data.get()) {
SkDebugf("Warning: could not create embedded stream.\n");
break;