aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/mem.c
diff options
context:
space:
mode:
authorBodo Möller <bodo@openssl.org>1999-07-09 16:27:30 +0000
committerBodo Möller <bodo@openssl.org>1999-07-09 16:27:30 +0000
commit777ab7e6110837ef2b1db5b5a67c754ce89e1e0b (patch)
tree07c27ea988e3445b55690f4981bbe47c7b5a3a07 /crypto/mem.c
parenta026fd201fbc4d8e4b1b531496bab29b1919189e (diff)
downloadopenssl-777ab7e6110837ef2b1db5b5a67c754ce89e1e0b.tar.gz
Fix memory checking.
Diffstat (limited to 'crypto/mem.c')
-rw-r--r--crypto/mem.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/crypto/mem.c b/crypto/mem.c
index 01f189bfc9..8a74507716 100644
--- a/crypto/mem.c
+++ b/crypto/mem.c
@@ -63,11 +63,21 @@
#include <openssl/lhash.h>
#include "cryptlib.h"
-#ifdef CRYPTO_MDEBUG
-static int mh_mode=CRYPTO_MEM_CHECK_ON;
-#else
+/* #ifdef CRYPTO_MDEBUG */
+/* static int mh_mode=CRYPTO_MEM_CHECK_ON; */
+/* #else */
static int mh_mode=CRYPTO_MEM_CHECK_OFF;
-#endif
+/* #endif */
+/* State CRYPTO_MEM_CHECK_ON exists only temporarily when the library
+ * thinks that certain allocations should not be checked (e.g. the data
+ * structures used for memory checking). It is not suitable as an initial
+ * state: the library will unexpectedly enable memory checking when it
+ * executes one of those sections that want to disable checking
+ * temporarily.
+ *
+ * State CRYPTO_MEM_CHECK_ENABLE without ..._ON makes no sense whatsoever.
+ */
+
static unsigned long order=0;
static LHASH *mh=NULL;
@@ -88,19 +98,23 @@ int CRYPTO_mem_ctrl(int mode)
CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
switch (mode)
{
- case CRYPTO_MEM_CHECK_ON:
- mh_mode|=CRYPTO_MEM_CHECK_ON;
+ /* for applications: */
+ case CRYPTO_MEM_CHECK_ON: /* aka MemCheck_start() */
+ mh_mode = CRYPTO_MEM_CHECK_ON|CRYPTO_MEM_CHECK_ENABLE;
break;
- case CRYPTO_MEM_CHECK_OFF:
- mh_mode&= ~CRYPTO_MEM_CHECK_ON;
+ case CRYPTO_MEM_CHECK_OFF: /* aka MemCheck_stop() */
+ mh_mode = 0;
break;
- case CRYPTO_MEM_CHECK_DISABLE:
+
+ /* switch off temporarily (for library-internal use): */
+ case CRYPTO_MEM_CHECK_DISABLE: /* aka MemCheck_off() */
mh_mode&= ~CRYPTO_MEM_CHECK_ENABLE;
break;
- case CRYPTO_MEM_CHECK_ENABLE:
+ case CRYPTO_MEM_CHECK_ENABLE: /* aka MemCheck_on() */
if (mh_mode&CRYPTO_MEM_CHECK_ON)
mh_mode|=CRYPTO_MEM_CHECK_ENABLE;
break;
+
default:
break;
}