From 4fae386cb0563a0c05c2817a5ccb3c18e6d62d8d Mon Sep 17 00:00:00 2001 From: Rich Salz Date: Wed, 16 Dec 2015 23:02:47 -0500 Subject: [PATCH 1/1] Cleanup CRYPTO_{push,pop}_info 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 --- crypto/asn1/tasn_new.c | 25 +++++++++---------------- crypto/bio/b_print.c | 2 -- crypto/err/err.c | 4 ---- crypto/mem_dbg.c | 24 ++++-------------------- include/openssl/crypto.h | 11 ++++++----- util/libeay.num | 6 +++--- 6 files changed, 22 insertions(+), 50 deletions(-) diff --git a/crypto/asn1/tasn_new.c b/crypto/asn1/tasn_new.c index 668f6419d1..9362ca2662 100644 --- a/crypto/asn1/tasn_new.c +++ b/crypto/asn1/tasn_new.c @@ -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; } diff --git a/crypto/bio/b_print.c b/crypto/bio/b_print.c index f82b0781cc..e0855a6c39 100644 --- a/crypto/bio/b_print.c +++ b/crypto/bio/b_print.c @@ -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); } diff --git a/crypto/err/err.c b/crypto/err/err.c index 236f8ac546..e487e980cb 100644 --- a/crypto/err/err.c +++ b/crypto/err/err.c @@ -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++; diff --git a/crypto/mem_dbg.c b/crypto/mem_dbg.c index 06d3f6734d..924652a6cb 100644 --- a/crypto/mem_dbg.c +++ b/crypto/mem_dbg.c @@ -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) diff --git a/include/openssl/crypto.h b/include/openssl/crypto.h index 70feb7fa71..e71214e955 100644 --- a/include/openssl/crypto.h +++ b/include/openssl/crypto.h @@ -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; diff --git a/util/libeay.num b/util/libeay.num index 698c938d9a..cc1aa718c6 100755 --- a/util/libeay.num +++ b/util/libeay.num @@ -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: -- 2.34.1