summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/mem_dbg.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/mem_dbg.c')
-rw-r--r--src/lib/libcrypto/mem_dbg.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/lib/libcrypto/mem_dbg.c b/src/lib/libcrypto/mem_dbg.c
index ea94eee6f4..9221df00bd 100644
--- a/src/lib/libcrypto/mem_dbg.c
+++ b/src/lib/libcrypto/mem_dbg.c
@@ -102,6 +102,8 @@ typedef struct app_mem_info_st
102 int references; 102 int references;
103 } APP_INFO; 103 } APP_INFO;
104 104
105static void app_info_free(APP_INFO *);
106
105static LHASH *amih=NULL; /* hash-table with those app_mem_info_st's 107static LHASH *amih=NULL; /* hash-table with those app_mem_info_st's
106 * that are at the top of their thread's stack 108 * that are at the top of their thread's stack
107 * (with `thread' as key); 109 * (with `thread' as key);
@@ -140,6 +142,18 @@ static unsigned long disabling_thread = 0; /* Valid iff num_disable > 0.
140 * thread named in disabling_thread). 142 * thread named in disabling_thread).
141 */ 143 */
142 144
145static 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
143int CRYPTO_mem_ctrl(int mode) 157int CRYPTO_mem_ctrl(int mode)
144 { 158 {
145 int ret=mh_mode; 159 int ret=mh_mode;
@@ -502,9 +516,7 @@ void CRYPTO_dbg_free(void *addr, int before_p)
502 mp->order, mp->addr, mp->num); 516 mp->order, mp->addr, mp->num);
503#endif 517#endif
504 if (mp->app_info != NULL) 518 if (mp->app_info != NULL)
505 { 519 app_info_free(mp->app_info);
506 mp->app_info->references--;
507 }
508 OPENSSL_free(mp); 520 OPENSSL_free(mp);
509 } 521 }
510 522
@@ -669,7 +681,6 @@ static IMPLEMENT_LHASH_DOALL_ARG_FN(print_leak, const MEM *, MEM_LEAK *)
669void CRYPTO_mem_leaks(BIO *b) 681void CRYPTO_mem_leaks(BIO *b)
670 { 682 {
671 MEM_LEAK ml; 683 MEM_LEAK ml;
672 char buf[80];
673 684
674 if (mh == NULL && amih == NULL) 685 if (mh == NULL && amih == NULL)
675 return; 686 return;
@@ -684,9 +695,8 @@ void CRYPTO_mem_leaks(BIO *b)
684 (char *)&ml); 695 (char *)&ml);
685 if (ml.chunks != 0) 696 if (ml.chunks != 0)
686 { 697 {
687 snprintf(buf,sizeof buf,"%ld bytes leaked in %d chunks\n", 698 BIO_printf(b,"%ld bytes leaked in %d chunks\n",
688 ml.bytes,ml.chunks); 699 ml.bytes,ml.chunks);
689 BIO_puts(b,buf);
690 } 700 }
691 else 701 else
692 { 702 {