#include <curl/curl.h>
#include "urldata.h"
+#include "curl_threads.h"
#include "curlx/fopen.h" /* for CURLX_FOPEN_LOW(), CURLX_FREOPEN_LOW() */
#ifdef USE_BACKTRACE
static char membuf[KEEPSIZE];
static size_t memwidx = 0; /* write index */
+#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
+static bool dbg_mutex_init = 0;
+static curl_mutex_t dbg_mutex;
+#endif
+
/* LeakSantizier (LSAN) calls _exit() instead of exit() when a leak is detected
on exit so the logfile must be closed explicitly or data could be lost.
Though _exit() does not call atexit handlers such as this, LSAN's call to
fclose(curl_dbg_logfile);
}
curl_dbg_logfile = NULL;
+#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
+ if(dbg_mutex_init) {
+ Curl_mutex_destroy(&dbg_mutex);
+ dbg_mutex_init = FALSE;
+ }
+#endif
}
#ifdef USE_BACKTRACE
static void error_bt_callback(void *data, const char *message,
setbuf(curl_dbg_logfile, (char *)NULL);
#endif
}
+#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
+ if(!dbg_mutex_init) {
+ dbg_mutex_init = TRUE;
+ Curl_mutex_init(&dbg_mutex);
+ }
+#endif
#ifdef USE_BACKTRACE
btstate = backtrace_create_state(NULL, 0, error_bt_callback, NULL);
#endif
nchars = (int)sizeof(buf) - 1;
if(nchars > 0) {
+#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
+ bool lock_mutex = dbg_mutex_init;
+ if(lock_mutex)
+ Curl_mutex_acquire(&dbg_mutex);
+#endif
if(KEEPSIZE - nchars < memwidx) {
/* flush */
fwrite(membuf, 1, memwidx, curl_dbg_logfile);
}
memcpy(&membuf[memwidx], buf, nchars);
memwidx += nchars;
+#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
+ if(lock_mutex)
+ Curl_mutex_release(&dbg_mutex);
+#endif
}
}