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

Side by Side Diff: src/codec/SkCodec_libbmp.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 | « src/codec/SkCodec_libbmp.h ('k') | src/codec/SkCodec_libgif.cpp » ('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_libbmp.h" 8 #include "SkCodec_libbmp.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 */ 101 */
102 SkCodec* SkBmpCodec::NewFromIco(SkStream* stream) { 102 SkCodec* SkBmpCodec::NewFromIco(SkStream* stream) {
103 return SkBmpCodec::NewFromStream(stream, true); 103 return SkBmpCodec::NewFromStream(stream, true);
104 } 104 }
105 105
106 /* 106 /*
107 * 107 *
108 * Read enough of the stream to initialize the SkBmpCodec. Returns a bool 108 * Read enough of the stream to initialize the SkBmpCodec. Returns a bool
109 * representing success or failure. If it returned true, and codecOut was 109 * representing success or failure. If it returned true, and codecOut was
110 * not NULL, it will be set to a new SkBmpCodec. 110 * not NULL, it will be set to a new SkBmpCodec.
111 * Does *not* take ownership of the passed in SkStream.
111 * 112 *
112 */ 113 */
113 bool SkBmpCodec::ReadHeader(SkStream* stream, bool isIco, SkCodec** codecOut) { 114 bool SkBmpCodec::ReadHeader(SkStream* stream, bool isIco, SkCodec** codecOut) {
114 // Header size constants 115 // Header size constants
115 static const uint32_t kBmpHeaderBytes = 14; 116 static const uint32_t kBmpHeaderBytes = 14;
116 static const uint32_t kBmpHeaderBytesPlusFour = kBmpHeaderBytes + 4; 117 static const uint32_t kBmpHeaderBytesPlusFour = kBmpHeaderBytes + 4;
117 static const uint32_t kBmpOS2V1Bytes = 12; 118 static const uint32_t kBmpOS2V1Bytes = 12;
118 static const uint32_t kBmpOS2V2Bytes = 64; 119 static const uint32_t kBmpOS2V2Bytes = 64;
119 static const uint32_t kBmpInfoBaseBytes = 16; 120 static const uint32_t kBmpInfoBaseBytes = 16;
120 static const uint32_t kBmpInfoV1Bytes = 40; 121 static const uint32_t kBmpInfoV1Bytes = 40;
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 return true; 490 return true;
490 } 491 }
491 492
492 /* 493 /*
493 * 494 *
494 * Creates a bmp decoder 495 * Creates a bmp decoder
495 * Reads enough of the stream to determine the image format 496 * Reads enough of the stream to determine the image format
496 * 497 *
497 */ 498 */
498 SkCodec* SkBmpCodec::NewFromStream(SkStream* stream, bool isIco) { 499 SkCodec* SkBmpCodec::NewFromStream(SkStream* stream, bool isIco) {
500 SkAutoTDelete<SkStream> streamDeleter(stream);
499 SkCodec* codec = NULL; 501 SkCodec* codec = NULL;
500 if (ReadHeader(stream, isIco, &codec)) { 502 if (ReadHeader(stream, isIco, &codec)) {
503 // codec has taken ownership of stream, so we do not need to
504 // delete it.
505 SkASSERT(codec);
506 streamDeleter.detach();
501 return codec; 507 return codec;
502 } 508 }
503 return NULL; 509 return NULL;
504 } 510 }
505 511
506 /* 512 /*
507 * 513 *
508 * Creates an instance of the decoder 514 * Creates an instance of the decoder
509 * Called only by NewFromStream 515 * Called only by NewFromStream
510 * 516 *
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 uint32_t alphaBit = 1132 uint32_t alphaBit =
1127 (srcBuffer.get()[quotient] >> shift) & 0x1; 1133 (srcBuffer.get()[quotient] >> shift) & 0x1;
1128 dstRow[x] &= alphaBit - 1; 1134 dstRow[x] &= alphaBit - 1;
1129 } 1135 }
1130 } 1136 }
1131 } 1137 }
1132 1138
1133 // Finished decoding the entire image 1139 // Finished decoding the entire image
1134 return kSuccess; 1140 return kSuccess;
1135 } 1141 }
OLDNEW
« no previous file with comments | « src/codec/SkCodec_libbmp.h ('k') | src/codec/SkCodec_libgif.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698