diff options
author | John Norrbin <Johnex@users.noreply.github.com> | 2019-01-04 19:24:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-04 19:24:59 +0100 |
commit | 1e848d2e4eaa5664d99b0e59f124f1eabf039f05 (patch) | |
tree | 1a0e2bbe0dfc7e7a263bb96627d714f4def3cd01 | |
parent | 779ec4dedcc62204a4d2acecb528a24931313a3d (diff) | |
download | portable-1e848d2e4eaa5664d99b0e59f124f1eabf039f05.tar.gz portable-1e848d2e4eaa5664d99b0e59f124f1eabf039f05.tar.bz2 portable-1e848d2e4eaa5664d99b0e59f124f1eabf039f05.zip |
Handle malloc returning null
Locks are required for multi-threading. If memory can't be allocated, exit the program with memory error. If we let the program continue, it will deadlock in the next part of the code anyway so better end it before.
-rw-r--r-- | crypto/compat/crypto_lock_win.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/crypto/compat/crypto_lock_win.c b/crypto/compat/crypto_lock_win.c index e995726..b3b1858 100644 --- a/crypto/compat/crypto_lock_win.c +++ b/crypto/compat/crypto_lock_win.c | |||
@@ -1,6 +1,7 @@ | |||
1 | /* $OpenBSD: crypto_lock.c,v 1.1 2018/11/11 06:41:28 bcook Exp $ */ | 1 | /* $OpenBSD: crypto_lock.c,v 1.1 2018/11/11 06:41:28 bcook Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2018 Brent Cook <bcook@openbsd.org> | 3 | * Copyright (c) 2019 Brent Cook <bcook@openbsd.org> |
4 | * Copyright (c) 2019 John Norrbin <jlnorrbin@johnex.se> | ||
4 | * | 5 | * |
5 | * Permission to use, copy, modify, and distribute this software for any | 6 | * Permission to use, copy, modify, and distribute this software for any |
6 | * purpose with or without fee is hereby granted, provided that the above | 7 | * purpose with or without fee is hereby granted, provided that the above |
@@ -29,8 +30,9 @@ CRYPTO_lock(int mode, int type, const char *file, int line) | |||
29 | 30 | ||
30 | if (locks[type] == NULL) { | 31 | if (locks[type] == NULL) { |
31 | LPCRITICAL_SECTION lcs = malloc(sizeof(CRITICAL_SECTION)); | 32 | LPCRITICAL_SECTION lcs = malloc(sizeof(CRITICAL_SECTION)); |
33 | if (lcs == NULL) exit(ENOMEM); | ||
32 | InitializeCriticalSection(lcs); | 34 | InitializeCriticalSection(lcs); |
33 | if (InterlockedCompareExchangePointer((void **)&locks[type], (void *)lcs, NULL) != NULL) { | 35 | if (InterlockedCompareExchangePointer((PVOID*)&locks[type], (PVOID)lcs, NULL) != NULL) { |
34 | DeleteCriticalSection(lcs); | 36 | DeleteCriticalSection(lcs); |
35 | free(lcs); | 37 | free(lcs); |
36 | } | 38 | } |