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}
This commit is contained in:
Ilya Nikolaevskiy
2019-04-26 12:37:37 +02:00
committed by Commit Bot
parent 9656a2e5d6
commit 40409c141a
2 changed files with 6 additions and 4 deletions

View File

@ -27,7 +27,9 @@ rtc_source_set("aligned_malloc") {
"aligned_malloc.cc",
"aligned_malloc.h",
]
deps = []
deps = [
"..:checks",
]
}
rtc_source_set("fifo_buffer") {

View File

@ -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 @@ void* AlignedMalloc(size_t size, size_t alignment) {
// 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.