Crash with error message if failed to allocate memory via AlignedMalloc
Bug: webrtc:10573
Change-Id: I26d443a0422e7bad7148d2acf422f0dfdf4dcb8e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/134218
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27795}
diff --git a/rtc_base/memory/BUILD.gn b/rtc_base/memory/BUILD.gn
index 3f70fca..1e3eb08 100644
--- a/rtc_base/memory/BUILD.gn
+++ b/rtc_base/memory/BUILD.gn
@@ -27,7 +27,9 @@
"aligned_malloc.cc",
"aligned_malloc.h",
]
- deps = []
+ deps = [
+ "..:checks",
+ ]
}
rtc_source_set("fifo_buffer") {
diff --git a/rtc_base/memory/aligned_malloc.cc b/rtc_base/memory/aligned_malloc.cc
index c893c96..5de8dab 100644
--- a/rtc_base/memory/aligned_malloc.cc
+++ b/rtc_base/memory/aligned_malloc.cc
@@ -10,6 +10,8 @@
#include "rtc_base/memory/aligned_malloc.h"
+#include "rtc_base/checks.h"
+
#include <stdlib.h> // for free, malloc
#include <string.h> // for memcpy
@@ -61,9 +63,7 @@
// A pointer to the start of the memory must be stored so that it can be
// retreived for deletion, ergo the sizeof(uintptr_t).
void* memory_pointer = malloc(size + sizeof(uintptr_t) + alignment - 1);
- if (memory_pointer == NULL) {
- return NULL;
- }
+ RTC_CHECK(memory_pointer) << "Couldn't allocate memory in AlignedMalloc";
// Aligning after the sizeof(uintptr_t) bytes will leave room for the header
// in the same memory block.