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

Unified Diff: sandbox/win/src/sandbox_nt_util.cc

Issue 556293002: Reorganize sandbox operator new, add a comment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 3 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: sandbox/win/src/sandbox_nt_util.cc
diff --git a/sandbox/win/src/sandbox_nt_util.cc b/sandbox/win/src/sandbox_nt_util.cc
index ed1d908ad6907d7397026dbc91f6d2403f0132c7..28ddd47bff43262a9043d163e575c194909d1870 100644
--- a/sandbox/win/src/sandbox_nt_util.cc
+++ b/sandbox/win/src/sandbox_nt_util.cc
@@ -547,17 +547,23 @@ void* operator new(size_t size, sandbox::AllocationType type,
void* near_to) {
using namespace sandbox;
+ void* result = NULL;
if (NT_ALLOC == type) {
- if (!InitHeap())
- return NULL;
-
- // Use default flags for the allocation.
- return g_nt.RtlAllocateHeap(sandbox::g_heap, 0, size);
+ if (InitHeap()) {
+ // Use default flags for the allocation.
+ result = g_nt.RtlAllocateHeap(sandbox::g_heap, 0, size);
+ }
} else if (NT_PAGE == type) {
- return AllocateNearTo(near_to, size);
+ result = AllocateNearTo(near_to, size);
+ } else {
+ NOTREACHED_NT();
}
- NOTREACHED_NT();
- return NULL;
+
+ // TODO: Returning NULL from operator new has undefined behavior, but
+ // the Allocate() functions called above can return NULL. Consider checking
+ // for NULL here and crashing or throwing.
+
+ return result;
}
void operator delete(void* memory, sandbox::AllocationType type) {
« 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