Cleanup CRYPTO_{push,pop}_info
authorRich Salz <rsalz@akamai.com>
Thu, 17 Dec 2015 04:02:47 +0000 (23:02 -0500)
committerRich Salz <rsalz@openssl.org>
Tue, 22 Dec 2015 14:11:07 +0000 (09:11 -0500)
Rename to OPENSSL_mem_debug_{push,pop}.
Remove simple calls; keep only calls used in recursive functions.
Ensure we always push, to simplify so that we can always pop

Reviewed-by: Richard Levitte <levitte@openssl.org>
crypto/asn1/tasn_new.c
crypto/bio/b_print.c
crypto/err/err.c
crypto/mem_dbg.c
include/openssl/crypto.h
util/libeay.num

index 668f6419d1cb63b00945937642098a7d3c815f81..9362ca2662e254ff5f8fffdf67b725f238f6a8ce 100644 (file)
@@ -103,8 +103,7 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed)
         asn1_cb = 0;
 
 #ifdef CRYPTO_MDEBUG
-    if (it->sname)
-        CRYPTO_push_info(it->sname);
+    OPENSSL_mem_debug_push(it->sname ? it->sname : "asn1_item_embed_new");
 #endif
 
     switch (it->itype) {
@@ -137,8 +136,7 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed)
                 goto auxerr;
             if (i == 2) {
 #ifdef CRYPTO_MDEBUG
-                if (it->sname)
-                    CRYPTO_pop_info();
+                OPENSSL_mem_debug_pop();
 #endif
                 return 1;
             }
@@ -163,8 +161,7 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed)
                 goto auxerr;
             if (i == 2) {
 #ifdef CRYPTO_MDEBUG
-                if (it->sname)
-                    CRYPTO_pop_info();
+                OPENSSL_mem_debug_pop();
 #endif
                 return 1;
             }
@@ -188,16 +185,14 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed)
         break;
     }
 #ifdef CRYPTO_MDEBUG
-    if (it->sname)
-        CRYPTO_pop_info();
+    OPENSSL_mem_debug_pop();
 #endif
     return 1;
 
  memerr:
     ASN1err(ASN1_F_ASN1_ITEM_EMBED_NEW, ERR_R_MALLOC_FAILURE);
 #ifdef CRYPTO_MDEBUG
-    if (it->sname)
-        CRYPTO_pop_info();
+    OPENSSL_mem_debug_pop();
 #endif
     return 0;
 
@@ -205,8 +200,7 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed)
     ASN1err(ASN1_F_ASN1_ITEM_EMBED_NEW, ASN1_R_AUX_ERROR);
     ASN1_item_ex_free(pval, it);
 #ifdef CRYPTO_MDEBUG
-    if (it->sname)
-        CRYPTO_pop_info();
+    OPENSSL_mem_debug_pop();
 #endif
     return 0;
 
@@ -266,8 +260,8 @@ static int asn1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
         return 1;
     }
 #ifdef CRYPTO_MDEBUG
-    if (tt->field_name)
-        CRYPTO_push_info(tt->field_name);
+    OPENSSL_mem_debug_push(tt->field_name
+            ? tt->field_name : "asn1_template_new");
 #endif
     /* If SET OF or SEQUENCE OF, its a STACK */
     if (tt->flags & ASN1_TFLG_SK_MASK) {
@@ -286,8 +280,7 @@ static int asn1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
     ret = asn1_item_embed_new(pval, it, embed);
  done:
 #ifdef CRYPTO_MDEBUG
-    if (it->sname)
-        CRYPTO_pop_info();
+    OPENSSL_mem_debug_pop();
 #endif
     return ret;
 }
index f82b0781cc98a52933e16a1ed2df85c4e5abc799..e0855a6c392ac7324985c72e24a702329a9038a7 100644 (file)
@@ -767,7 +767,6 @@ int BIO_vprintf(BIO *bio, const char *format, va_list args)
     int ignored;
 
     dynbuf = NULL;
-    CRYPTO_push_info("doapr()");
     _dopr(&hugebufp, &dynbuf, &hugebufsize, &retlen, &ignored, format, args);
     if (dynbuf) {
         ret = BIO_write(bio, dynbuf, (int)retlen);
@@ -775,7 +774,6 @@ int BIO_vprintf(BIO *bio, const char *format, va_list args)
     } else {
         ret = BIO_write(bio, hugebuf, (int)retlen);
     }
-    CRYPTO_pop_info();
     return (ret);
 }
 
index 236f8ac5463a451065a6b84cdacc8491925e0457..e487e980cb94cf861423de11cf342b5c4f0c729c 100644 (file)
@@ -276,9 +276,7 @@ static LHASH_OF(ERR_STRING_DATA) *get_hash(int create, int lockit)
     if (lockit)
         CRYPTO_w_lock(CRYPTO_LOCK_ERR);
     if (!int_error_hash && create) {
-        CRYPTO_push_info("get_hash (err.c)");
         int_error_hash = lh_ERR_STRING_DATA_new();
-        CRYPTO_pop_info();
     }
     if (int_error_hash != NULL)
         ret = int_error_hash;
@@ -323,9 +321,7 @@ static LHASH_OF(ERR_STATE) *int_thread_get(int create, int lockit)
     if (lockit)
         CRYPTO_w_lock(CRYPTO_LOCK_ERR);
     if (!int_thread_hash && create) {
-        CRYPTO_push_info("int_thread_get (err.c)");
         int_thread_hash = lh_ERR_STATE_new();
-        CRYPTO_pop_info();
     }
     if (int_thread_hash != NULL) {
         int_thread_hash_references++;
index 06d3f6734d79bdb265ba599d075de43201b4ce83..924652a6cb02d078b5e698ee55756af4af3b4b7e 100644 (file)
@@ -145,9 +145,8 @@ typedef struct app_mem_info_st
  * For application-defined information (static C-string `info')
  * to be displayed in memory leak list.
  * Each thread has its own stack.  For applications, there is
- *   CRYPTO_push_info("...")     to push an entry,
- *   CRYPTO_pop_info()           to pop an entry,
- *   CRYPTO_remove_all_info()    to pop all entries.
+ *   OPENSSL_mem_debug_push("...")     to push an entry,
+ *   OPENSSL_mem_debug_pop()     to pop an entry,
  */
 {
     CRYPTO_THREADID threadid;
@@ -384,7 +383,7 @@ static APP_INFO *pop_info(void)
     return (ret);
 }
 
-int CRYPTO_push_info_(const char *info, const char *file, int line)
+int CRYPTO_mem_debug_push(const char *info, const char *file, int line)
 {
     APP_INFO *ami, *amim;
     int ret = 0;
@@ -420,7 +419,7 @@ int CRYPTO_push_info_(const char *info, const char *file, int line)
     return (ret);
 }
 
-int CRYPTO_pop_info(void)
+int CRYPTO_mem_debug_pop(void)
 {
     int ret = 0;
 
@@ -435,21 +434,6 @@ int CRYPTO_pop_info(void)
     return (ret);
 }
 
-int CRYPTO_remove_all_info(void)
-{
-    int ret = 0;
-
-    if (is_MemCheck_on()) {     /* _must_ be true */
-        MemCheck_off();         /* obtain MALLOC2 lock */
-
-        while (pop_info() != NULL)
-            ret++;
-
-        MemCheck_on();          /* release MALLOC2 lock */
-    }
-    return (ret);
-}
-
 static unsigned long break_order_num = 0;
 void CRYPTO_dbg_malloc(void *addr, size_t num, const char *file, int line,
                        int before_p)
index 70feb7fa7178bc3e49434a039ea731042896f712..e71214e9551b1b868a72a2c1d95684391746c9ee 100644 (file)
@@ -507,11 +507,12 @@ void OPENSSL_cleanse(void *ptr, size_t len);
 void CRYPTO_set_mem_debug_options(long bits);
 long CRYPTO_get_mem_debug_options(void);
 
-# define CRYPTO_push_info(info) \
-        CRYPTO_push_info_(info, __FILE__, __LINE__);
-int CRYPTO_push_info_(const char *info, const char *file, int line);
-int CRYPTO_pop_info(void);
-int CRYPTO_remove_all_info(void);
+# define OPENSSL_mem_debug_push(info) \
+        CRYPTO_mem_debug_push(info, __FILE__, __LINE__)
+# define OPENSSL_mem_debug_pop() \
+        CRYPTO_mem_debug_pop()
+int CRYPTO_mem_debug_push(const char *info, const char *file, int line);
+int CRYPTO_mem_debug_pop(void);
 
 /*
  * Default debugging functions (enabled by CRYPTO_malloc_debug_init() macro;
index 698c938d9affd9f5c5e5b523c6f2576dd373290d..cc1aa718c65ba8cee5ce3f56701d80559b20c095 100755 (executable)
@@ -1680,12 +1680,12 @@ PKCS7_get_smimecap                      2154    1_1_0   EXIST::FUNCTION:
 PKCS7_sign                              2155   1_1_0   EXIST::FUNCTION:
 PKCS7_add_attrib_smimecap               2156   1_1_0   EXIST::FUNCTION:
 CRYPTO_dbg_set_options                  2157   1_1_0   EXIST::FUNCTION:
-CRYPTO_remove_all_info                  2158   1_1_0   EXIST::FUNCTION:
+CRYPTO_remove_all_info                  2158   1_1_0   NOEXIST::FUNCTION:
 CRYPTO_get_mem_debug_functions          2159   1_1_0   EXIST::FUNCTION:
 CRYPTO_is_mem_check_on                  2160   1_1_0   EXIST::FUNCTION:
 CRYPTO_set_mem_debug_functions          2161   1_1_0   EXIST::FUNCTION:
-CRYPTO_pop_info                         2162   1_1_0   EXIST::FUNCTION:
-CRYPTO_push_info_                       2163   1_1_0   EXIST::FUNCTION:
+CRYPTO_mem_debug_pop                    2162   1_1_0   EXIST::FUNCTION:
+CRYPTO_mem_debug_push                   2163   1_1_0   EXIST::FUNCTION:
 CRYPTO_set_mem_debug_options            2164   1_1_0   EXIST::FUNCTION:
 PEM_write_PKCS8PrivateKey_nid           2165   1_1_0   EXIST::FUNCTION:STDIO
 PEM_write_bio_PKCS8PrivateKey_nid       2166   1_1_0   EXIST:!VMS:FUNCTION: