aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Satiro <raysatiro@yahoo.com>2016-03-16 19:13:42 -0400
committerJay Satiro <raysatiro@yahoo.com>2016-03-16 19:13:42 -0400
commit80015cdd52145bd95b98e0e456540c6da3120f98 (patch)
treed4cd9195c28a352c27943dcc16f422d44d5d0baf
parent0e18b8b1071d1101e41bd78d69db64d1514383fc (diff)
version: thread safety
-rw-r--r--lib/easy.c6
-rw-r--r--lib/version.c22
2 files changed, 26 insertions, 2 deletions
diff --git a/lib/easy.c b/lib/easy.c
index fc7b40b27..0b6d93361 100644
--- a/lib/easy.c
+++ b/lib/easy.c
@@ -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;
}
diff --git a/lib/version.c b/lib/version.c
index 7f14fa5ca..f693feeda 100644
--- a/lib/version.c
+++ b/lib/version.c
@@ -64,13 +64,25 @@
#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;
}