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

Side by Side 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, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/codec/SkCodec_libbmp.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCodec.h" 8 #include "SkCodec.h"
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkCodec_libbmp.h" 10 #include "SkCodec_libbmp.h"
(...skipping 14 matching lines...) Expand all
25 { SkGifCodec::IsGif, SkGifCodec::NewFromStream }, 25 { SkGifCodec::IsGif, SkGifCodec::NewFromStream },
26 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, 26 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream },
27 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream }, 27 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream },
28 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream } 28 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream }
29 }; 29 };
30 30
31 SkCodec* SkCodec::NewFromStream(SkStream* stream) { 31 SkCodec* SkCodec::NewFromStream(SkStream* stream) {
32 if (!stream) { 32 if (!stream) {
33 return NULL; 33 return NULL;
34 } 34 }
35
36 SkAutoTDelete<SkStream> streamDeleter(stream);
35 37
36 SkCodec* codec = NULL; 38 SkAutoTDelete<SkCodec> codec(NULL);
37 for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) { 39 for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) {
38 DecoderProc proc = gDecoderProcs[i]; 40 DecoderProc proc = gDecoderProcs[i];
39 const bool correctFormat = proc.IsFormat(stream); 41 const bool correctFormat = proc.IsFormat(stream);
40 if (!stream->rewind()) { 42 if (!stream->rewind()) {
41 return NULL; 43 return NULL;
42 } 44 }
43 if (correctFormat) { 45 if (correctFormat) {
44 codec = proc.NewFromStream(stream); 46 codec.reset(proc.NewFromStream(streamDeleter.detach()));
45 break; 47 break;
46 } 48 }
47 } 49 }
48 50
49 // Set the max size at 128 megapixels (512 MB for kN32). 51 // Set the max size at 128 megapixels (512 MB for kN32).
50 // This is about 4x smaller than a test image that takes a few minutes for 52 // This is about 4x smaller than a test image that takes a few minutes for
51 // dm to decode and draw. 53 // dm to decode and draw.
52 const int32_t maxSize = 1 << 27; 54 const int32_t maxSize = 1 << 27;
53 if (codec != NULL && 55 if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize) {
54 codec->getInfo().width() * codec->getInfo().height() > maxSize) {
55 SkCodecPrintf("Error: Image size too large, cannot decode.\n"); 56 SkCodecPrintf("Error: Image size too large, cannot decode.\n");
56 return NULL; 57 return NULL;
57 } else { 58 } else {
58 return codec; 59 return codec.detach();
59 } 60 }
60 } 61 }
61 62
62 SkCodec* SkCodec::NewFromData(SkData* data) { 63 SkCodec* SkCodec::NewFromData(SkData* data) {
63 if (!data) { 64 if (!data) {
64 return NULL; 65 return NULL;
65 } 66 }
66 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data))); 67 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data)));
67 } 68 }
68 69
(...skipping 15 matching lines...) Expand all
84 return kNoRewindNecessary_RewindState; 85 return kNoRewindNecessary_RewindState;
85 } 86 }
86 return fStream->rewind() ? kRewound_RewindState 87 return fStream->rewind() ? kRewound_RewindState
87 : kCouldNotRewind_RewindState; 88 : kCouldNotRewind_RewindState;
88 } 89 }
89 90
90 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo) { 91 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo) {
91 fScanlineDecoder.reset(this->onGetScanlineDecoder(dstInfo)); 92 fScanlineDecoder.reset(this->onGetScanlineDecoder(dstInfo));
92 return fScanlineDecoder.get(); 93 return fScanlineDecoder.get();
93 } 94 }
OLDNEW
« 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