diff options
Diffstat (limited to 'src/lib/libcrypto/mem_dbg.c')
-rw-r--r-- | src/lib/libcrypto/mem_dbg.c | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/src/lib/libcrypto/mem_dbg.c b/src/lib/libcrypto/mem_dbg.c index 57bd08f65d..ea94eee6f4 100644 --- a/src/lib/libcrypto/mem_dbg.c +++ b/src/lib/libcrypto/mem_dbg.c | |||
@@ -102,8 +102,6 @@ typedef struct app_mem_info_st | |||
102 | int references; | 102 | int references; |
103 | } APP_INFO; | 103 | } APP_INFO; |
104 | 104 | ||
105 | static void app_info_free(APP_INFO *); | ||
106 | |||
107 | static LHASH *amih=NULL; /* hash-table with those app_mem_info_st's | 105 | static LHASH *amih=NULL; /* hash-table with those app_mem_info_st's |
108 | * that are at the top of their thread's stack | 106 | * that are at the top of their thread's stack |
109 | * (with `thread' as key); | 107 | * (with `thread' as key); |
@@ -142,18 +140,6 @@ static unsigned long disabling_thread = 0; /* Valid iff num_disable > 0. | |||
142 | * thread named in disabling_thread). | 140 | * thread named in disabling_thread). |
143 | */ | 141 | */ |
144 | 142 | ||
145 | static void app_info_free(APP_INFO *inf) | ||
146 | { | ||
147 | if (--(inf->references) <= 0) | ||
148 | { | ||
149 | if (inf->next != NULL) | ||
150 | { | ||
151 | app_info_free(inf->next); | ||
152 | } | ||
153 | OPENSSL_free(inf); | ||
154 | } | ||
155 | } | ||
156 | |||
157 | int CRYPTO_mem_ctrl(int mode) | 143 | int CRYPTO_mem_ctrl(int mode) |
158 | { | 144 | { |
159 | int ret=mh_mode; | 145 | int ret=mh_mode; |
@@ -516,7 +502,9 @@ void CRYPTO_dbg_free(void *addr, int before_p) | |||
516 | mp->order, mp->addr, mp->num); | 502 | mp->order, mp->addr, mp->num); |
517 | #endif | 503 | #endif |
518 | if (mp->app_info != NULL) | 504 | if (mp->app_info != NULL) |
519 | app_info_free(mp->app_info); | 505 | { |
506 | mp->app_info->references--; | ||
507 | } | ||
520 | OPENSSL_free(mp); | 508 | OPENSSL_free(mp); |
521 | } | 509 | } |
522 | 510 | ||
@@ -597,6 +585,8 @@ static void print_leak(const MEM *m, MEM_LEAK *l) | |||
597 | struct tm *lcl = NULL; | 585 | struct tm *lcl = NULL; |
598 | unsigned long ti; | 586 | unsigned long ti; |
599 | 587 | ||
588 | #define BUF_REMAIN (sizeof buf - (size_t)(bufp - buf)) | ||
589 | |||
600 | if(m->addr == (char *)l->bio) | 590 | if(m->addr == (char *)l->bio) |
601 | return; | 591 | return; |
602 | 592 | ||
@@ -604,22 +594,22 @@ static void print_leak(const MEM *m, MEM_LEAK *l) | |||
604 | { | 594 | { |
605 | lcl = localtime(&m->time); | 595 | lcl = localtime(&m->time); |
606 | 596 | ||
607 | sprintf(bufp, "[%02d:%02d:%02d] ", | 597 | snprintf(bufp, BUF_REMAIN, "[%02d:%02d:%02d] ", |
608 | lcl->tm_hour,lcl->tm_min,lcl->tm_sec); | 598 | lcl->tm_hour,lcl->tm_min,lcl->tm_sec); |
609 | bufp += strlen(bufp); | 599 | bufp += strlen(bufp); |
610 | } | 600 | } |
611 | 601 | ||
612 | sprintf(bufp, "%5lu file=%s, line=%d, ", | 602 | snprintf(bufp, BUF_REMAIN, "%5lu file=%s, line=%d, ", |
613 | m->order,m->file,m->line); | 603 | m->order,m->file,m->line); |
614 | bufp += strlen(bufp); | 604 | bufp += strlen(bufp); |
615 | 605 | ||
616 | if (options & V_CRYPTO_MDEBUG_THREAD) | 606 | if (options & V_CRYPTO_MDEBUG_THREAD) |
617 | { | 607 | { |
618 | sprintf(bufp, "thread=%lu, ", m->thread); | 608 | snprintf(bufp, BUF_REMAIN, "thread=%lu, ", m->thread); |
619 | bufp += strlen(bufp); | 609 | bufp += strlen(bufp); |
620 | } | 610 | } |
621 | 611 | ||
622 | sprintf(bufp, "number=%d, address=%08lX\n", | 612 | snprintf(bufp, BUF_REMAIN, "number=%d, address=%08lX\n", |
623 | m->num,(unsigned long)m->addr); | 613 | m->num,(unsigned long)m->addr); |
624 | bufp += strlen(bufp); | 614 | bufp += strlen(bufp); |
625 | 615 | ||
@@ -641,7 +631,7 @@ static void print_leak(const MEM *m, MEM_LEAK *l) | |||
641 | 631 | ||
642 | ami_cnt++; | 632 | ami_cnt++; |
643 | memset(buf,'>',ami_cnt); | 633 | memset(buf,'>',ami_cnt); |
644 | sprintf(buf + ami_cnt, | 634 | snprintf(buf + ami_cnt, sizeof buf - ami_cnt, |
645 | " thread=%lu, file=%s, line=%d, info=\"", | 635 | " thread=%lu, file=%s, line=%d, info=\"", |
646 | amip->thread, amip->file, amip->line); | 636 | amip->thread, amip->file, amip->line); |
647 | buf_len=strlen(buf); | 637 | buf_len=strlen(buf); |
@@ -653,10 +643,11 @@ static void print_leak(const MEM *m, MEM_LEAK *l) | |||
653 | } | 643 | } |
654 | else | 644 | else |
655 | { | 645 | { |
656 | strcpy(buf + buf_len, amip->info); | 646 | strlcpy(buf + buf_len, amip->info, |
647 | sizeof buf - buf_len); | ||
657 | buf_len = strlen(buf); | 648 | buf_len = strlen(buf); |
658 | } | 649 | } |
659 | sprintf(buf + buf_len, "\"\n"); | 650 | snprintf(buf + buf_len, sizeof buf - buf_len, "\"\n"); |
660 | 651 | ||
661 | BIO_puts(l->bio,buf); | 652 | BIO_puts(l->bio,buf); |
662 | 653 | ||
@@ -678,6 +669,7 @@ static IMPLEMENT_LHASH_DOALL_ARG_FN(print_leak, const MEM *, MEM_LEAK *) | |||
678 | void CRYPTO_mem_leaks(BIO *b) | 669 | void CRYPTO_mem_leaks(BIO *b) |
679 | { | 670 | { |
680 | MEM_LEAK ml; | 671 | MEM_LEAK ml; |
672 | char buf[80]; | ||
681 | 673 | ||
682 | if (mh == NULL && amih == NULL) | 674 | if (mh == NULL && amih == NULL) |
683 | return; | 675 | return; |
@@ -692,8 +684,9 @@ void CRYPTO_mem_leaks(BIO *b) | |||
692 | (char *)&ml); | 684 | (char *)&ml); |
693 | if (ml.chunks != 0) | 685 | if (ml.chunks != 0) |
694 | { | 686 | { |
695 | BIO_printf(b,"%ld bytes leaked in %d chunks\n", | 687 | snprintf(buf,sizeof buf,"%ld bytes leaked in %d chunks\n", |
696 | ml.bytes,ml.chunks); | 688 | ml.bytes,ml.chunks); |
689 | BIO_puts(b,buf); | ||
697 | } | 690 | } |
698 | else | 691 | else |
699 | { | 692 | { |