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

Unified Diff: base/memory/discardable_shared_memory.cc

Issue 1741403002: base: Avoid calling VirtualAlloc with 0 length. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/discardable_shared_memory.cc
diff --git a/base/memory/discardable_shared_memory.cc b/base/memory/discardable_shared_memory.cc
index 7449f462e68ea4936b6c381239b316da59862594..65b6513b0a211371abca07d7dda3a8603460d130 100644
--- a/base/memory/discardable_shared_memory.cc
+++ b/base/memory/discardable_shared_memory.cc
@@ -232,7 +232,8 @@ DiscardableSharedMemory::LockResult DiscardableSharedMemory::Lock(
}
#elif defined(OS_WIN)
if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
- if (!VirtualAlloc(reinterpret_cast<char*>(shared_memory_.memory()) +
+ if (length &&
penny 2016/02/28 21:49:10 if (!length) return PURGED; Unlock is fine as i
reveman 2016/02/29 16:36:59 Done. Note: memory segments are initially locked
+ !VirtualAlloc(reinterpret_cast<char*>(shared_memory_.memory()) +
AlignToPageSize(sizeof(SharedState)) + offset,
length, MEM_RESET_UNDO, PAGE_READWRITE)) {
return PURGED;
@@ -271,7 +272,8 @@ void DiscardableSharedMemory::Unlock(size_t offset, size_t length) {
// function needs to match the Lock behaviour (MEM_RESET_UNDO) to properly
// implement memory pinning. It needs to bias towards preserving the
// contents of memory between an Unlock and next Lock.
- if (!VirtualAlloc(reinterpret_cast<char*>(shared_memory_.memory()) +
+ if (length &&
+ !VirtualAlloc(reinterpret_cast<char*>(shared_memory_.memory()) +
AlignToPageSize(sizeof(SharedState)) + offset,
length, MEM_RESET, PAGE_READWRITE)) {
DPLOG(ERROR) << "VirtualAlloc() MEM_RESET failed in Unlock()";
« 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