summaryrefslogtreecommitdiff
path: root/src/lib/libssl/src/crypto/mem_dbg.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/src/crypto/mem_dbg.c')
-rw-r--r--src/lib/libssl/src/crypto/mem_dbg.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/src/lib/libssl/src/crypto/mem_dbg.c b/src/lib/libssl/src/crypto/mem_dbg.c
index 14770c0733..a399485300 100644
--- a/src/lib/libssl/src/crypto/mem_dbg.c
+++ b/src/lib/libssl/src/crypto/mem_dbg.c
@@ -640,19 +640,54 @@ void CRYPTO_mem_leaks(BIO *b)
640 MEM_LEAK ml; 640 MEM_LEAK ml;
641 char buf[80]; 641 char buf[80];
642 642
643 if (mh == NULL) return; 643 if (mh == NULL && amih == NULL)
644 return;
644 ml.bio=b; 645 ml.bio=b;
645 ml.bytes=0; 646 ml.bytes=0;
646 ml.chunks=0; 647 ml.chunks=0;
647 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2); 648 MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */
648 lh_doall_arg(mh,(void (*)())print_leak,(char *)&ml); 649 if (mh != NULL)
649 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2); 650 lh_doall_arg(mh,(void (*)())print_leak,(char *)&ml);
650 if (ml.chunks != 0) 651 if (ml.chunks != 0)
651 { 652 {
652 sprintf(buf,"%ld bytes leaked in %d chunks\n", 653 sprintf(buf,"%ld bytes leaked in %d chunks\n",
653 ml.bytes,ml.chunks); 654 ml.bytes,ml.chunks);
654 BIO_puts(b,buf); 655 BIO_puts(b,buf);
655 } 656 }
657 else
658 {
659 /* Make sure that, if we found no leaks, memory-leak debugging itself
660 * does not introduce memory leaks (which might irritate
661 * external debugging tools).
662 * (When someone enables leak checking, but does not call
663 * this function, we declare it to be their fault.)
664 *
665 * XXX This should be in CRYPTO_mem_leaks_cb,
666 * and CRYPTO_mem_leaks should be implemented by
667 * using CRYPTO_mem_leaks_cb.
668 * (Also their should be a variant of lh_doall_arg
669 * that takes a function pointer instead of a void *;
670 * this would obviate the ugly and illegal
671 * void_fn_to_char kludge in CRYPTO_mem_leaks_cb.
672 * Otherwise the code police will come and get us.)
673 */
674 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
675 if (mh != NULL)
676 {
677 lh_free(mh);
678 mh = NULL;
679 }
680 if (amih != NULL)
681 {
682 if (lh_num_items(amih) == 0)
683 {
684 lh_free(amih);
685 amih = NULL;
686 }
687 }
688 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
689 }
690 MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */
656 691
657#if 0 692#if 0
658 lh_stats_bio(mh,b); 693 lh_stats_bio(mh,b);