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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/BlobBytesConsumer.cpp

Issue 2702403007: Fix BlobBytesConsumer leak (Closed)
Patch Set: Created 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/fetch/BlobBytesConsumer.h" 5 #include "modules/fetch/BlobBytesConsumer.h"
6 6
7 #include "core/loader/ThreadableLoader.h" 7 #include "core/loader/ThreadableLoader.h"
8 #include "modules/fetch/BytesConsumerForDataConsumerHandle.h" 8 #include "modules/fetch/BytesConsumerForDataConsumerHandle.h"
9 #include "platform/blob/BlobData.h" 9 #include "platform/blob/BlobData.h"
10 #include "platform/blob/BlobRegistry.h" 10 #include "platform/blob/BlobRegistry.h"
(...skipping 19 matching lines...) Expand all
30 m_loader = nullptr; 30 m_loader = nullptr;
31 } 31 }
32 m_state = PublicState::Closed; 32 m_state = PublicState::Closed;
33 } 33 }
34 } 34 }
35 35
36 BlobBytesConsumer::BlobBytesConsumer(ExecutionContext* executionContext, 36 BlobBytesConsumer::BlobBytesConsumer(ExecutionContext* executionContext,
37 PassRefPtr<BlobDataHandle> blobDataHandle) 37 PassRefPtr<BlobDataHandle> blobDataHandle)
38 : BlobBytesConsumer(executionContext, std::move(blobDataHandle), nullptr) {} 38 : BlobBytesConsumer(executionContext, std::move(blobDataHandle), nullptr) {}
39 39
40 BlobBytesConsumer::~BlobBytesConsumer() {} 40 BlobBytesConsumer::~BlobBytesConsumer() {
41 if (!m_blobURL.isEmpty())
42 BlobRegistry::revokePublicBlobURL(m_blobURL);
43 }
41 44
42 BytesConsumer::Result BlobBytesConsumer::beginRead(const char** buffer, 45 BytesConsumer::Result BlobBytesConsumer::beginRead(const char** buffer,
43 size_t* available) { 46 size_t* available) {
44 *buffer = nullptr; 47 *buffer = nullptr;
45 *available = 0; 48 *available = 0;
46 49
47 if (m_state == PublicState::Closed) { 50 if (m_state == PublicState::Closed) {
48 // It's possible that |cancel| has been called before the first 51 // It's possible that |cancel| has been called before the first
49 // |beginRead| call. That's why we need to check this condition 52 // |beginRead| call. That's why we need to check this condition
50 // before checking |isClean()|. 53 // before checking |isClean()|.
51 return Result::Done; 54 return Result::Done;
52 } 55 }
53 56
54 if (isClean()) { 57 if (isClean()) {
55 KURL m_blobURL = 58 DCHECK(m_blobURL.isEmpty());
59 m_blobURL =
56 BlobURL::createPublicURL(getExecutionContext()->getSecurityOrigin()); 60 BlobURL::createPublicURL(getExecutionContext()->getSecurityOrigin());
57 if (m_blobURL.isEmpty()) { 61 if (m_blobURL.isEmpty()) {
58 error(); 62 error();
59 } else { 63 } else {
60 BlobRegistry::registerPublicBlobURL( 64 BlobRegistry::registerPublicBlobURL(
61 getExecutionContext()->getSecurityOrigin(), m_blobURL, 65 getExecutionContext()->getSecurityOrigin(), m_blobURL,
62 m_blobDataHandle); 66 m_blobDataHandle);
63 67
64 // m_loader is non-null only in tests. 68 // m_loader is non-null only in tests.
65 if (!m_loader) 69 if (!m_loader)
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 void BlobBytesConsumer::clear() { 301 void BlobBytesConsumer::clear() {
298 DCHECK_NE(m_state, PublicState::ReadableOrWaiting); 302 DCHECK_NE(m_state, PublicState::ReadableOrWaiting);
299 if (m_loader) { 303 if (m_loader) {
300 m_loader->cancel(); 304 m_loader->cancel();
301 m_loader = nullptr; 305 m_loader = nullptr;
302 } 306 }
303 m_client = nullptr; 307 m_client = nullptr;
304 } 308 }
305 309
306 } // namespace blink 310 } // namespace blink
OLDNEW
« 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