diff options
author | Sverker Eriksson <[email protected]> | 2014-02-19 16:39:39 +0100 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2014-02-19 16:40:06 +0100 |
commit | a40cc981b6b13d9a6514d2c326eb5f4904f80983 (patch) | |
tree | 9f7a55f90f6e8eab069a9b259523c5c5511bf5c4 /lib/crypto/c_src | |
parent | 8c17e706e212b859f1a248f43c8091e8d541b08e (diff) | |
parent | c4e046b9d46da5e718ddf4ef5c863315dea8d274 (diff) | |
download | otp-a40cc981b6b13d9a6514d2c326eb5f4904f80983.tar.gz otp-a40cc981b6b13d9a6514d2c326eb5f4904f80983.tar.bz2 otp-a40cc981b6b13d9a6514d2c326eb5f4904f80983.zip |
Merge branch 'sverk/crypto/nomem-abort'
OTP-11725
* sverk/crypto/nomem-abort:
crypto: Abort VM if out of memory
Diffstat (limited to 'lib/crypto/c_src')
-rw-r--r-- | lib/crypto/c_src/crypto_callback.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/crypto/c_src/crypto_callback.c b/lib/crypto/c_src/crypto_callback.c index 81106b4cc2..a08dcec463 100644 --- a/lib/crypto/c_src/crypto_callback.c +++ b/lib/crypto/c_src/crypto_callback.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2012. All Rights Reserved. + * Copyright Ericsson AB 2014. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -17,6 +17,7 @@ * %CopyrightEnd% */ +#include <stdio.h> #include <string.h> #include <openssl/opensslconf.h> @@ -51,13 +52,28 @@ DLLEXPORT struct crypto_callbacks* get_crypto_callbacks(int nlocks); static ErlNifRWLock** lock_vec = NULL; /* Static locks used by openssl */ +static void nomem(size_t size, const char* op) +{ + fprintf(stderr, "Out of memory abort. Crypto failed to %s %zu bytes.\r\n", + op, size); + abort(); +} + static void* crypto_alloc(size_t size) { - return enif_alloc(size); + void *ret = enif_alloc(size); + + if (!ret && size) + nomem(size, "allocate"); + return ret; } static void* crypto_realloc(void* ptr, size_t size) { - return enif_realloc(ptr, size); + void* ret = enif_realloc(ptr, size); + + if (!ret && size) + nomem(size, "reallocate"); + return ret; } static void crypto_free(void* ptr) { |