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

Unified Diff: chrome/common/resource_dispatcher.cc

Issue 115396: Fix a memory leak in ResourceDispatcher... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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 | « chrome/common/resource_dispatcher.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/resource_dispatcher.cc
===================================================================
--- chrome/common/resource_dispatcher.cc (revision 15966)
+++ chrome/common/resource_dispatcher.cc (working copy)
@@ -276,6 +276,8 @@
// This might happen for kill()ed requests on the webkit end, so perhaps it
// shouldn't be a warning...
DLOG(WARNING) << "Got response for a nonexistant or finished request";
+ // Release resources in the message if it is a data message.
+ ReleaseResourcesInDataMessage(message);
return true;
}
@@ -467,6 +469,17 @@
PendingRequestList::iterator it = pending_requests_.find(request_id);
if (it == pending_requests_.end())
return false;
+
+ // Iterate through the deferred message queue and clean up the messages.
+ PendingRequestInfo& request_info = it->second;
+ MessageQueue& q = request_info.deferred_message_queue;
+ while (!q.empty()) {
+ IPC::Message* m = q.front();
+ ReleaseResourcesInDataMessage(*m);
+ q.pop_front();
+ delete m;
+ }
+
pending_requests_.erase(it);
return true;
}
@@ -559,3 +572,24 @@
return false;
}
+
+void ResourceDispatcher::ReleaseResourcesInDataMessage(
+ const IPC::Message& message) {
+ void* iter = NULL;
+ int request_id;
+ if (!message.ReadInt(&iter, &request_id)) {
+ NOTREACHED() << "malformed resource message";
+ return;
+ }
+
+ // If the message contains a shared memory handle, we should close the
+ // handle or there will be a memory leak.
+ if (message.type() == ViewMsg_Resource_DataReceived::ID) {
+ base::SharedMemoryHandle shm_handle;
+ if (IPC::ParamTraits<base::SharedMemoryHandle>::Read(&message,
+ &iter,
+ &shm_handle)) {
+ base::SharedMemory::CloseHandle(shm_handle);
+ }
+ }
+}
« no previous file with comments | « chrome/common/resource_dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698