diff options
author | Kenny Root <kroot@google.com> | 2015-10-02 16:09:15 -0700 |
---|---|---|
committer | Kenny Root <kroot@google.com> | 2015-10-02 16:09:49 -0700 |
commit | fe7305364c3369f9222a61646c5c9842eae9bceb (patch) | |
tree | 360ada970b7bb1046ae069d253ba24d9622eb3ad /src/crypto/test/malloc.cc | |
parent | 691ef9d0ff0ece39ffd6a58960a7cd195ef584ae (diff) | |
parent | b452bce3bf2034466cee6206ebf3994409468ee4 (diff) | |
download | external_boringssl-fe7305364c3369f9222a61646c5c9842eae9bceb.zip external_boringssl-fe7305364c3369f9222a61646c5c9842eae9bceb.tar.gz external_boringssl-fe7305364c3369f9222a61646c5c9842eae9bceb.tar.bz2 |
Merge mnc-dr-dev-plus-aosp into mnc-ub-dev
This pulls in the latest version of BoringSSL.
Change-Id: I0ab5c73d60f41a696c9a828fac87670aaca10dec
Diffstat (limited to 'src/crypto/test/malloc.cc')
-rw-r--r-- | src/crypto/test/malloc.cc | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/crypto/test/malloc.cc b/src/crypto/test/malloc.cc index 9ffdf01..898f2a7 100644 --- a/src/crypto/test/malloc.cc +++ b/src/crypto/test/malloc.cc @@ -34,6 +34,8 @@ #if defined(__linux__) && defined(OPENSSL_GLIBC) && !defined(OPENSSL_ARM) && \ !defined(OPENSSL_AARCH64) && !defined(OPENSSL_ASAN) +#include <errno.h> +#include <signal.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> @@ -45,14 +47,14 @@ /* This file defines overrides for the standard allocation functions that allow * a given allocation to be made to fail for testing. If the program is run * with MALLOC_NUMBER_TO_FAIL set to a base-10 number then that allocation will - * return NULL. If MALLOC_ABORT_ON_FAIL is also defined then the allocation - * will abort() rather than return NULL. + * return NULL. If MALLOC_BREAK_ON_FAIL is also defined then the allocation + * will signal SIGTRAP rather than return NULL. * * This code is not thread safe. */ static uint64_t current_malloc_count = 0; static uint64_t malloc_number_to_fail = 0; -static char failure_enabled = 0, abort_on_fail = 0; +static char failure_enabled = 0, break_on_fail = 0; static int in_call = 0; extern "C" { @@ -95,7 +97,7 @@ static int should_fail_allocation() { std::set_new_handler(cpp_new_handler); } } - abort_on_fail = (NULL != getenv("MALLOC_ABORT_ON_FAIL")); + break_on_fail = (NULL != getenv("MALLOC_BREAK_ON_FAIL")); init = 1; } @@ -108,8 +110,8 @@ static int should_fail_allocation() { should_fail = (current_malloc_count == malloc_number_to_fail); current_malloc_count++; - if (should_fail && abort_on_fail) { - abort(); + if (should_fail && break_on_fail) { + raise(SIGTRAP); } return should_fail; } @@ -118,6 +120,7 @@ extern "C" { void *malloc(size_t size) { if (should_fail_allocation()) { + errno = ENOMEM; return NULL; } @@ -126,6 +129,7 @@ void *malloc(size_t size) { void *calloc(size_t num_elems, size_t size) { if (should_fail_allocation()) { + errno = ENOMEM; return NULL; } @@ -134,6 +138,7 @@ void *calloc(size_t num_elems, size_t size) { void *realloc(void *ptr, size_t size) { if (should_fail_allocation()) { + errno = ENOMEM; return NULL; } |