unload dll / destroy hash ctxs at shutdown
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
diff --git a/src/global.c b/src/global.c
index de7e42d..d085089 100644
--- a/src/global.c
+++ b/src/global.c
@@ -79,6 +79,9 @@ void git_threads_shutdown(void)
TlsFree(_tls_index);
_tls_init = 0;
git_mutex_free(&git__mwindow_mutex);
+
+ /* Shut down any subsystems that have global state */
+ git_hash_global_shutdown();
}
git_global_st *git__global_state(void)
@@ -131,6 +134,9 @@ void git_threads_shutdown(void)
{
pthread_key_delete(_tls_key);
_tls_init = 0;
+
+ /* Shut down any subsystems that have global state */
+ git_hash_global_shutdown();
}
git_global_st *git__global_state(void)
diff --git a/src/global.h b/src/global.h
index 1025cf7..b117714 100644
--- a/src/global.h
+++ b/src/global.h
@@ -14,6 +14,8 @@
# define GIT_MEMORY_BARRIER MemoryBarrier()
#elif defined(GIT_THREADS)
# define GIT_MEMORY_BARRIER __sync_synchronize()
+#else
+# define GIT_MEMORY_BARRIER /* noop */
#endif
typedef struct {
diff --git a/src/hash.h b/src/hash.h
index 0e543ed..127be28 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -13,6 +13,7 @@ typedef struct git_hash_prov git_hash_prov;
typedef struct git_hash_ctx git_hash_ctx;
int git_hash_global_init(void);
+void git_hash_global_shutdown(void);
int git_hash_ctx_init(git_hash_ctx *ctx);
void git_hash_ctx_cleanup(git_hash_ctx *ctx);
diff --git a/src/hash/hash_generic.h b/src/hash/hash_generic.h
index 92c9cb9..7c4be78 100644
--- a/src/hash/hash_generic.h
+++ b/src/hash/hash_generic.h
@@ -17,6 +17,7 @@ struct git_hash_ctx {
};
#define git_hash_global_init() 0
+#define git_hash_global_shutdown() /* noop */
#define git_hash_ctx_init(ctx) git_hash_init(ctx)
#define git_hash_ctx_cleanup(ctx)
diff --git a/src/hash/hash_openssl.h b/src/hash/hash_openssl.h
index 39c47ae..3ae49a7 100644
--- a/src/hash/hash_openssl.h
+++ b/src/hash/hash_openssl.h
@@ -17,6 +17,7 @@ struct git_hash_ctx {
};
#define git_hash_global_init() 0
+#define git_hash_global_shutdown() /* noop */
#define git_hash_ctx_init(ctx) git_hash_init(ctx)
#define git_hash_ctx_cleanup(ctx)
diff --git a/src/hash/hash_ppc.h b/src/hash/hash_ppc.h
index df6570e..935f73f 100644
--- a/src/hash/hash_ppc.h
+++ b/src/hash/hash_ppc.h
@@ -21,6 +21,7 @@ struct git_hash_ctx {
};
#define git_hash_global_init() 0
+#define git_hash_global_shutdown() /* noop */
#define git_hash_ctx_init(ctx) git_hash_init(ctx)
#define git_hash_ctx_cleanup(ctx)
diff --git a/src/hash/hash_win32.c b/src/hash/hash_win32.c
index c490942..a89dffa 100644
--- a/src/hash/hash_win32.c
+++ b/src/hash/hash_win32.c
@@ -26,6 +26,8 @@ GIT_INLINE(int) hash_cng_prov_init(void)
char dll_path[MAX_PATH];
DWORD dll_path_len, size_len;
+ return -1;
+
/* Only use CNG on Windows 2008 / Vista SP1 or better (Windows 6.0 SP1) */
version_test.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
version_test.dwMajorVersion = 6;
@@ -79,6 +81,14 @@ GIT_INLINE(int) hash_cng_prov_init(void)
return 0;
}
+GIT_INLINE(void) hash_cng_prov_shutdown(void)
+{
+ hash_prov.prov.cng.close_algorithm_provider(hash_prov.prov.cng.handle, 0);
+ FreeLibrary(hash_prov.prov.cng.dll);
+
+ hash_prov.type = INVALID;
+}
+
/* Initialize CryptoAPI */
GIT_INLINE(int) hash_cryptoapi_prov_init()
{
@@ -89,6 +99,13 @@ GIT_INLINE(int) hash_cryptoapi_prov_init()
return 0;
}
+GIT_INLINE(void) hash_cryptoapi_prov_shutdown(void)
+{
+ CryptReleaseContext(hash_prov.prov.cryptoapi.handle, 0);
+
+ hash_prov.type = INVALID;
+}
+
int git_hash_global_init()
{
int error = 0;
@@ -102,6 +119,14 @@ int git_hash_global_init()
return error;
}
+void git_hash_global_shutdown()
+{
+ if (hash_prov.type == CNG)
+ hash_cng_prov_shutdown();
+ else if(hash_prov.type == CRYPTOAPI)
+ hash_cryptoapi_prov_shutdown();
+}
+
/* CryptoAPI: available in Windows XP and newer */
GIT_INLINE(int) hash_ctx_cryptoapi_init(git_hash_ctx *ctx)