]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
global_init: debug builds allocates a byte in init
authorDaniel Stenberg <daniel@haxx.se>
Mon, 4 Jan 2021 23:03:57 +0000 (00:03 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 6 Jan 2021 14:13:45 +0000 (15:13 +0100)
... to make build tools/valgrind warn if no curl_global_cleanup is
called.

This is conditionally only done for debug builds with the env variable
CURL_GLOBAL_INIT set.

Closes #6410

lib/easy.c
tests/runtests.pl

index 311946bdf1bd7a59aded31a569b83236f475e6d6..04e59144ba4859086865cd4d5411e510c8edc0a5 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -124,6 +124,10 @@ curl_wcsdup_callback Curl_cwcsdup = (curl_wcsdup_callback)_wcsdup;
 #  pragma warning(default:4232) /* MSVC extension, dllimport identity */
 #endif
 
+#ifdef DEBUGBUILD
+static char *leakpointer;
+#endif
+
 /**
  * curl_global_init() globally initializes curl given a bitwise set of the
  * different features of what to initialize.
@@ -190,6 +194,12 @@ static CURLcode global_init(long flags, bool memoryfuncs)
 
   init_flags = flags;
 
+#ifdef DEBUGBUILD
+  if(getenv("CURL_GLOBAL_INIT"))
+    /* alloc data that will leak if *cleanup() is not called! */
+    leakpointer = malloc(1);
+#endif
+
   return CURLE_OK;
 
   fail:
@@ -265,6 +275,9 @@ void curl_global_cleanup(void)
 #ifdef USE_WOLFSSH
   (void)wolfSSH_Cleanup();
 #endif
+#ifdef DEBUGBUILD
+  free(leakpointer);
+#endif
 
   init_flags  = 0;
 }
index 6c5edc84d86d555d3e3e01372d00992a37a3f480..0e0e26c3ca273c1bc4c0463de98568fe93c2f522 100755 (executable)
@@ -381,6 +381,7 @@ if (!$USER) {
 $ENV{'CURL_MEMDEBUG'} = $memdump;
 $ENV{'CURL_ENTROPY'}="12345678";
 $ENV{'CURL_FORCETIME'}=1; # for debug NTLM magic
+$ENV{'CURL_GLOBAL_INIT'}=1; # debug curl_global_init/cleanup use
 $ENV{'HOME'}=$pwd;
 $ENV{'COLUMNS'}=79; # screen width!