Move & split opensslconf.h.in
[openssl.git] / crypto / mem_dbg.c
index 36ce5f4eb41c6d764de2dc21b92e00c04ddfe151..67a48001ec042c827011dc1382978d46efeb4568 100644 (file)
@@ -306,8 +306,6 @@ static int mem_cmp(const MEM *a, const MEM *b)
 #endif
 }
 
-static IMPLEMENT_LHASH_COMP_FN(mem, MEM)
-
 static unsigned long mem_hash(const MEM *a)
 {
     size_t ret;
@@ -318,17 +316,11 @@ static unsigned long mem_hash(const MEM *a)
     return (ret);
 }
 
-static IMPLEMENT_LHASH_HASH_FN(mem, MEM)
-
-/* static int app_info_cmp(APP_INFO *a, APP_INFO *b) */
-static int app_info_cmp(const void *a_void, const void *b_void)
+static int app_info_cmp(const APP_INFO *a, const APP_INFO *b)
 {
-    return CRYPTO_THREADID_cmp(&((const APP_INFO *)a_void)->threadid,
-                               &((const APP_INFO *)b_void)->threadid);
+    return CRYPTO_THREADID_cmp(&a->threadid, &b->threadid);
 }
 
-static IMPLEMENT_LHASH_COMP_FN(app_info, APP_INFO)
-
 static unsigned long app_info_hash(const APP_INFO *a)
 {
     unsigned long ret;
@@ -339,31 +331,31 @@ static unsigned long app_info_hash(const APP_INFO *a)
     return (ret);
 }
 
-static IMPLEMENT_LHASH_HASH_FN(app_info, APP_INFO)
-
-static APP_INFO *pop_info(void)
+/* returns 1 if there was an info to pop, 0 if the stack was empty. */
+static int pop_info(void)
 {
     APP_INFO tmp;
-    APP_INFO *ret = NULL;
+    APP_INFO *current = NULL;
 
     if (amih != NULL) {
         CRYPTO_THREADID_current(&tmp.threadid);
-        if ((ret = lh_APP_INFO_delete(amih, &tmp)) != NULL) {
-            APP_INFO *next = ret->next;
+        if ((current = lh_APP_INFO_delete(amih, &tmp)) != NULL) {
+            APP_INFO *next = current->next;
 
             if (next != NULL) {
                 next->references++;
                 (void)lh_APP_INFO_insert(amih, next);
             }
-            if (--(ret->references) <= 0) {
-                ret->next = NULL;
+            if (--(current->references) <= 0) {
+                current->next = NULL;
                 if (next != NULL)
                     next->references--;
-                OPENSSL_free(ret);
+                OPENSSL_free(current);
             }
+            return 1;
         }
     }
-    return (ret);
+    return 0;
 }
 
 int CRYPTO_mem_debug_push(const char *info, const char *file, int line)
@@ -377,7 +369,7 @@ int CRYPTO_mem_debug_push(const char *info, const char *file, int line)
         if ((ami = OPENSSL_malloc(sizeof(*ami))) == NULL)
             goto err;
         if (amih == NULL) {
-            if ((amih = lh_APP_INFO_new()) == NULL) {
+            if ((amih = lh_APP_INFO_new(app_info_hash, app_info_cmp)) == NULL) {
                 OPENSSL_free(ami);
                 goto err;
             }
@@ -406,7 +398,7 @@ int CRYPTO_mem_debug_pop(void)
 
     if (mem_check_on()) {
         CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
-        ret = (pop_info() != NULL);
+        ret = pop_info();
         CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
     }
     return (ret);
@@ -435,7 +427,7 @@ void CRYPTO_mem_debug_malloc(void *addr, size_t num, int before_p,
                 return;
             }
             if (mh == NULL) {
-                if ((mh = lh_MEM_new()) == NULL) {
+                if ((mh = lh_MEM_new(mem_hash, mem_cmp)) == NULL) {
                     OPENSSL_free(addr);
                     OPENSSL_free(m);
                     addr = NULL;
@@ -554,7 +546,7 @@ typedef struct mem_leak_st {
     long bytes;
 } MEM_LEAK;
 
-static void print_leak_doall_arg(const MEM *m, MEM_LEAK *l)
+static void print_leak(const MEM *m, MEM_LEAK *l)
 {
     char buf[1024];
     char *bufp = buf;
@@ -639,7 +631,7 @@ static void print_leak_doall_arg(const MEM *m, MEM_LEAK *l)
 #endif
 }
 
-static IMPLEMENT_LHASH_DOALL_ARG_FN(print_leak, const MEM, MEM_LEAK)
+IMPLEMENT_LHASH_DOALL_ARG_CONST(MEM, MEM_LEAK);
 
 int CRYPTO_mem_leaks(BIO *b)
 {
@@ -655,7 +647,7 @@ int CRYPTO_mem_leaks(BIO *b)
     ml.chunks = 0;
     ml.seen = 0;
     if (mh != NULL)
-        lh_MEM_doall_arg(mh, LHASH_DOALL_ARG_FN(print_leak), MEM_LEAK, &ml);
+        lh_MEM_doall_MEM_LEAK(mh, print_leak, &ml);
     /* Don't count the BIO that was passed in as a "leak" */
     if (ml.seen && ml.chunks >= 1 && ml.bytes >= (int)sizeof (*b)) {
         ml.chunks--;