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

Side by Side Diff: base/allocator/winheap_stubs_win.cc

Issue 2377633002: corrected undefined behaviour when ptr is NULL in HeapFree (Closed)
Patch Set: added myself to authors file Created 4 years, 2 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 | « AUTHORS ('k') | 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 // This code should move into the default Windows shim once the win-specific 5 // This code should move into the default Windows shim once the win-specific
6 // allocation shim has been removed, and the generic shim has becaome the 6 // allocation shim has been removed, and the generic shim has becaome the
7 // default. 7 // default.
8 8
9 #include "winheap_stubs_win.h" 9 #include "winheap_stubs_win.h"
10 10
(...skipping 17 matching lines...) Expand all
28 } 28 }
29 29
30 } // namespace 30 } // namespace
31 31
32 void* WinHeapMalloc(size_t size) { 32 void* WinHeapMalloc(size_t size) {
33 if (size < kMaxWindowsAllocation) 33 if (size < kMaxWindowsAllocation)
34 return HeapAlloc(get_heap_handle(), 0, size); 34 return HeapAlloc(get_heap_handle(), 0, size);
35 return nullptr; 35 return nullptr;
36 } 36 }
37 37
38 void WinHeapFree(void* size) { 38 void WinHeapFree(void* ptr) {
39 HeapFree(get_heap_handle(), 0, size); 39 if (!ptr)
40 return;
41
42 HeapFree(get_heap_handle(), 0, ptr);
40 } 43 }
41 44
42 void* WinHeapRealloc(void* ptr, size_t size) { 45 void* WinHeapRealloc(void* ptr, size_t size) {
43 if (!ptr) 46 if (!ptr)
44 return WinHeapMalloc(size); 47 return WinHeapMalloc(size);
45 if (!size) { 48 if (!size) {
46 WinHeapFree(ptr); 49 WinHeapFree(ptr);
47 return nullptr; 50 return nullptr;
48 } 51 }
49 if (size < kMaxWindowsAllocation) 52 if (size < kMaxWindowsAllocation)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 _PNH nh = _query_new_handler(); 85 _PNH nh = _query_new_handler();
83 if (!nh) 86 if (!nh)
84 return false; 87 return false;
85 // Since exceptions are disabled, we don't really know if new_handler 88 // Since exceptions are disabled, we don't really know if new_handler
86 // failed. Assume it will abort if it fails. 89 // failed. Assume it will abort if it fails.
87 return nh(size) ? true : false; 90 return nh(size) ? true : false;
88 } 91 }
89 92
90 } // namespace allocator 93 } // namespace allocator
91 } // namespace base 94 } // namespace base
OLDNEW
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698