Cosmetic changes.
[openssl.git] / crypto / mem.c
index 8a74507716af6e2bee1852acf746178492578f4d..61fc1e184ed6b4e87765f2a22989e17e1c2f5faf 100644 (file)
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <openssl/crypto.h>
+#ifdef CRYPTO_MDEBUG_TIME
+# include <time.h>     
+#endif
 #include <openssl/buffer.h>
 #include <openssl/bio.h>
 #include <openssl/lhash.h>
@@ -88,7 +92,13 @@ typedef struct mem_st
        int num;
        const char *file;
        int line;
+#ifdef CRYPTO_MDEBUG_THREAD
+       unsigned long thread;
+#endif
        unsigned long order;
+#ifdef CRYPTO_MDEBUG_TIME
+       time_t time;
+#endif
        } MEM;
 
 int CRYPTO_mem_ctrl(int mode)
@@ -232,12 +242,18 @@ void *CRYPTO_dbg_malloc(int num, const char *file, int line)
                m->file=file;
                m->line=line;
                m->num=num;
+#ifdef CRYPTO_MDEBUG_THREAD
+               m->thread=CRYPTO_thread_id();
+#endif
                if (order == break_order_num)
                        {
                        /* BREAK HERE */
                        m->order=order;
                        }
                m->order=order++;
+#ifdef CRYPTO_MDEBUG_TIME
+               m->time=time(NULL);
+#endif
                if ((mm=(MEM *)lh_insert(mh,(char *)m)) != NULL)
                        {
                        /* Not good, but don't sweat it */
@@ -319,11 +335,35 @@ typedef struct mem_leak_st
 static void print_leak(MEM *m, MEM_LEAK *l)
        {
        char buf[128];
+#ifdef CRYPTO_MDEBUG_TIME
+       struct tm *lcl;
+#endif
 
        if(m->addr == (char *)l->bio)
            return;
-       sprintf(buf,"%5lu file=%s, line=%d, number=%d, address=%08lX\n",
-               m->order,m->file,m->line,m->num,(unsigned long)m->addr);
+
+#ifdef CRYPTO_MDEBUG_TIME
+       lcl = localtime(&m->time);
+#endif
+
+       sprintf(buf,
+#ifdef CRYPTO_MDEBUG_TIME
+               "[%02d:%02d:%02d] "
+#endif
+               "%5lu file=%s, line=%d, "
+#ifdef CRYPTO_MDEBUG_THREAD
+               "thread=%lu, "
+#endif
+               "number=%d, address=%08lX\n",
+#ifdef CRYPTO_MDEBUG_TIME
+               lcl->tm_hour,lcl->tm_min,lcl->tm_sec,
+#endif
+               m->order,m->file,m->line,
+#ifdef CRYPTO_MDEBUG_THREAD
+               m->thread,
+#endif
+               m->num,(unsigned long)m->addr);
+
        BIO_puts(l->bio,buf);
        l->chunks++;
        l->bytes+=m->num;