Browse Source

Memory debugging for non-Windows systems

bel 11 years ago
parent
commit
57c12b6ff3
1 changed files with 21 additions and 0 deletions
  1. 21 0
      src/civetweb.c

+ 21 - 0
src/civetweb.c

@@ -336,8 +336,13 @@ static void * mg_malloc_ex(size_t size, const char * file, unsigned line) {
         blockCount++;
         memory = (void *)(((char*)data)+sizeof(size_t));
     }
+
     sprintf(mallocStr, "MEM: %p %5u alloc   %7u %4u --- %s:%u\n", memory, size, totalMemUsed, blockCount, file, line);
+#if defined(_WIN32)
     OutputDebugStringA(mallocStr);
+#else
+    puts(mallocStr);
+#endif
 
     return memory;
 }
@@ -361,7 +366,11 @@ static void mg_free_ex(void * memory, const char * file, unsigned line) {
         totalMemUsed -= size;
         blockCount--;
         sprintf(mallocStr, "MEM: %p %5u free    %7u %4u --- %s:%u\n", memory, size, totalMemUsed, blockCount, file, line);
+#if defined(_WIN32)
         OutputDebugStringA(mallocStr);
+#else
+        puts(mallocStr);
+#endif
 
         free(data);
     }
@@ -381,14 +390,26 @@ static void * mg_realloc_ex(void * memory, size_t newsize, const char * file, un
             if (data) {
                 totalMemUsed -= oldsize;
                 sprintf(mallocStr, "MEM: %p %5u r-free  %7u %4u --- %s:%u\n", memory, oldsize, totalMemUsed, blockCount, file, line);
+#if defined(_WIN32)
                 OutputDebugStringA(mallocStr);
+#else
+                puts(mallocStr);
+#endif
                 totalMemUsed += newsize;
                 sprintf(mallocStr, "MEM: %p %5u r-alloc %7u %4u --- %s:%u\n", memory, newsize, totalMemUsed, blockCount, file, line);
+#if defined(_WIN32)
                 OutputDebugStringA(mallocStr);
+#else
+                puts(mallocStr);
+#endif
                 *(size_t*)data = newsize;
                 data = (void *)(((char*)data)+sizeof(size_t));
             } else {
+#if defined(_WIN32)
                 OutputDebugStringA("MEM: realloc failed\n");
+#else
+                puts("MEM: realloc failed\n");
+#endif
             }
         } else {
             data = mg_malloc_ex(newsize, file, line);