Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Unified Diff: src/codec/SkCodec_libico.cpp

Issue 1036873002: Fixing memory leak in ico decoder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkCodec_libico.cpp
diff --git a/src/codec/SkCodec_libico.cpp b/src/codec/SkCodec_libico.cpp
index 2adfa9cfde6157c97920fd59c2f9650094f3f549..6a62ed88666254b13466629d3ec85aeb20953dce 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;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698