]> granicus.if.org Git - curl/commitdiff
version: thread safety
authorJay Satiro <raysatiro@yahoo.com>
Wed, 16 Mar 2016 23:13:42 +0000 (19:13 -0400)
committerJay Satiro <raysatiro@yahoo.com>
Wed, 16 Mar 2016 23:13:42 +0000 (19:13 -0400)
lib/easy.c
lib/version.c

index fc7b40b2706d8d7c57314b6931f1809bcd0d336e..0b6d933619e4af24feebf93c51306a5496e3d70d 100644 (file)
@@ -79,6 +79,8 @@
 #include "curl_memory.h"
 #include "memdebug.h"
 
+void curl_version_init();
+
 /* win32_cleanup() is for win32 socket cleanup functionality, the opposite
    of win32_init() */
 static void win32_cleanup(void)
@@ -280,7 +282,9 @@ static CURLcode global_init(long flags, bool memoryfuncs)
   if(flags & CURL_GLOBAL_ACK_EINTR)
     Curl_ack_eintr = 1;
 
-  init_flags  = flags;
+  init_flags = flags;
+
+  curl_version_init();
 
   return CURLE_OK;
 }
index 7f14fa5cad151669d2ca8bb931c2b60421bf26f7..f693feedafb2aea1dcc062d091a68f7312351e25 100644 (file)
 #define CURL_LIBSSH2_VERSION LIBSSH2_VERSION
 #endif
 
+/* For thread safety purposes this function is called by global_init so that
+   the static data in both version functions is initialized. */
+void curl_version_init()
+{
+  curl_version();
+  curl_version_info(CURLVERSION_NOW);
+}
+
 char *curl_version(void)
 {
+  static bool initialized;
   static char version[200];
   char *ptr = version;
   size_t len;
   size_t left = sizeof(version);
 
+  if(initialized)
+    return version;
+
   strcpy(ptr, LIBCURL_NAME "/" LIBCURL_VERSION);
   len = strlen(ptr);
   left -= len;
@@ -160,6 +172,7 @@ char *curl_version(void)
   }
 #endif
 
+  initialized = true;
   return version;
 }
 
@@ -323,12 +336,18 @@ static curl_version_info_data version_info = {
 
 curl_version_info_data *curl_version_info(CURLversion stamp)
 {
+  static bool initialized;
 #ifdef USE_LIBSSH2
   static char ssh_buffer[80];
 #endif
-
 #ifdef USE_SSL
   static char ssl_buffer[80];
+#endif
+
+  if(initialized)
+    return &version_info;
+
+#ifdef USE_SSL
   Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
   version_info.ssl_version = ssl_buffer;
 #endif
@@ -370,5 +389,6 @@ curl_version_info_data *curl_version_info(CURLversion stamp)
 
   (void)stamp; /* avoid compiler warnings, we don't use this */
 
+  initialized = true;
   return &version_info;
 }