Commit 4fae386c authored by Rich Salz's avatar Rich Salz Committed by Rich Salz
Browse files

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: default avatarRichard Levitte <levitte@openssl.org>
parent c99de053
Loading
Loading
Loading
Loading
+9 −16
Original line number Diff line number Diff line
@@ -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;
}
+0 −2
Original line number Diff line number Diff line
@@ -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);
}

+0 −4
Original line number Diff line number Diff line
@@ -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++;
+4 −20
Original line number Diff line number Diff line
@@ -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)
+6 −5
Original line number Diff line number Diff line
@@ -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;
Loading