]> granicus.if.org Git - curl/commitdiff
enable memory debugging the same way the curl command line tool already does
authorDaniel Stenberg <daniel@haxx.se>
Fri, 14 May 2004 08:40:33 +0000 (08:40 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 14 May 2004 08:40:33 +0000 (08:40 +0000)
tests/libtest/first.c
tests/libtest/test.h

index d8bfdd19a256a54bbc25d640bd7e438797f7da4e..c4f35df22d70a19f5f3ac5647d7367a07892ac9a 100644 (file)
@@ -3,6 +3,7 @@
 #ifdef CURLDEBUG
 /* provide a proto for this debug function */
 extern void curl_memdebug(const char *);
+extern void curl_memlimit(int);
 #endif
 
 /* test is provided in the test code file */
@@ -13,6 +14,21 @@ char *arg2=NULL;
 int main(int argc, char **argv)
 {
   char *URL;
+
+#ifdef CURLDEBUG
+  /* this sends all memory debug messages to a logfile named memdump */
+  char *env = curl_getenv("CURL_MEMDEBUG");
+  if(env) {
+    curl_free(env);
+    curl_memdebug("memdump");
+  }
+  /* this enables the fail-on-alloc-number-N functionality */
+  env = curl_getenv("CURL_MEMLIMIT");
+  if(env) {
+    curl_memlimit(atoi(env));
+    curl_free(env);
+  }
+#endif
   if(argc< 2 ) {
     fprintf(stderr, "Pass URL as argument please\n");
     return 1;
@@ -24,8 +40,5 @@ int main(int argc, char **argv)
 
   fprintf(stderr, "URL: %s\n", URL);
 
-#ifdef CURLDEBUG
-  curl_memdebug("memdump");
-#endif
   return test(URL);
 }
index f0e13b20f5f2aad53879cd9412ddeaaa287bd722..a442ba4bd4d91a501724084534ab6de1361d7be6 100644 (file)
@@ -9,6 +9,7 @@
 #include <curl.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 
 #ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>