From 3286c408eccb18c525ca123383f3ebf5097441bc Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Fri, 28 Oct 2011 14:51:13 -0700 Subject: global: Properly use `git__` memory wrappers Ensure that all memory related functions (malloc, calloc, strdup, free, etc) are using their respective `git__` wrappers. --- src/errors.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/errors.c') diff --git a/src/errors.c b/src/errors.c index 60d774636..18afff3b5 100644 --- a/src/errors.c +++ b/src/errors.c @@ -70,9 +70,9 @@ void git___rethrow(const char *msg, ...) vsnprintf(new_error, sizeof(new_error), msg, va); va_end(va); - old_error = strdup(g_last_error); + old_error = git__strdup(g_last_error); snprintf(g_last_error, sizeof(g_last_error), "%s \n - %s", new_error, old_error); - free(old_error); + git__free(old_error); } void git___throw(const char *msg, ...) -- cgit v1.2.1 From a15c550db8b0552902e58c9bf2194005fb7fb0e9 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Wed, 16 Nov 2011 14:09:44 +0100 Subject: threads: Fix the shared global state with TLS See `global.c` for a description of what we're doing. When libgit2 is built with GIT_THREADS support, the threading system must be explicitly initialized with `git_threads_init()`. --- src/errors.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'src/errors.c') diff --git a/src/errors.c b/src/errors.c index 18afff3b5..81770e786 100644 --- a/src/errors.c +++ b/src/errors.c @@ -5,13 +5,9 @@ * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" -#include "git2/thread-utils.h" /* for GIT_TLS */ -#include "thread-utils.h" /* for GIT_TLS */ - +#include "global.h" #include -static GIT_TLS char g_last_error[1024]; - static struct { int num; const char *str; @@ -59,19 +55,26 @@ const char *git_strerror(int num) return "Unknown error"; } +#define ERROR_MAX_LEN 1024 + void git___rethrow(const char *msg, ...) { - char new_error[1024]; + char new_error[ERROR_MAX_LEN]; + char *last_error; char *old_error = NULL; va_list va; + last_error = GIT_GLOBAL->error.last; + va_start(va, msg); - vsnprintf(new_error, sizeof(new_error), msg, va); + vsnprintf(new_error, ERROR_MAX_LEN, msg, va); va_end(va); - old_error = git__strdup(g_last_error); - snprintf(g_last_error, sizeof(g_last_error), "%s \n - %s", new_error, old_error); + old_error = git__strdup(last_error); + + snprintf(last_error, ERROR_MAX_LEN, "%s \n - %s", new_error, old_error); + git__free(old_error); } @@ -80,19 +83,22 @@ void git___throw(const char *msg, ...) va_list va; va_start(va, msg); - vsnprintf(g_last_error, sizeof(g_last_error), msg, va); + vsnprintf(GIT_GLOBAL->error.last, ERROR_MAX_LEN, msg, va); va_end(va); } const char *git_lasterror(void) { - if (!g_last_error[0]) + char *last_error = GIT_GLOBAL->error.last; + + if (!last_error[0]) return NULL; - return g_last_error; + return last_error; } void git_clearerror(void) { - g_last_error[0] = '\0'; + char *last_error = GIT_GLOBAL->error.last; + last_error[0] = '\0'; } -- cgit v1.2.1