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

Unified Diff: src/codec/SkCodec.cpp

Issue 1058873006: Get rid of leaks in SkCodec::NewFromStream. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add comment that ReadHeader does not own SkStream. 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 | src/codec/SkCodec_libbmp.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkCodec.cpp
diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp
index 5604af8d3dce27067c0439c211872f66f6e2e832..7bc9146041e7f62b590f82ca44fdf2e3ff19f22e 100644
--- a/src/codec/SkCodec.cpp
+++ b/src/codec/SkCodec.cpp
@@ -32,8 +32,10 @@ SkCodec* SkCodec::NewFromStream(SkStream* stream) {
if (!stream) {
return NULL;
}
+
+ SkAutoTDelete<SkStream> streamDeleter(stream);
- SkCodec* codec = NULL;
+ SkAutoTDelete<SkCodec> codec(NULL);
for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) {
DecoderProc proc = gDecoderProcs[i];
const bool correctFormat = proc.IsFormat(stream);
@@ -41,7 +43,7 @@ SkCodec* SkCodec::NewFromStream(SkStream* stream) {
return NULL;
}
if (correctFormat) {
- codec = proc.NewFromStream(stream);
+ codec.reset(proc.NewFromStream(streamDeleter.detach()));
break;
}
}
@@ -50,12 +52,11 @@ SkCodec* SkCodec::NewFromStream(SkStream* stream) {
// This is about 4x smaller than a test image that takes a few minutes for
// dm to decode and draw.
const int32_t maxSize = 1 << 27;
- if (codec != NULL &&
- codec->getInfo().width() * codec->getInfo().height() > maxSize) {
+ if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize) {
SkCodecPrintf("Error: Image size too large, cannot decode.\n");
return NULL;
} else {
- return codec;
+ return codec.detach();
}
}
« no previous file with comments | « no previous file | src/codec/SkCodec_libbmp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698