summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-18 02:24:35 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-18 02:24:35 +0000
commit27ed294c7134c0de582007af3c915a635a6506cd (patch)
treea8380752441b222e957b1ed074e8040f88301510 /ext
parent588504b20f5cc880ad51827b93e571e32446e5db (diff)
win32ole: OLE uninitialize
* ext/win32ole/win32ole.c (ole_initialize): uninitialize OLE at thread ends. [Bug #2618] [ruby-core:27634] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38868 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/win32ole/win32ole.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c
index dcf0dd3..bebe115 100644
--- a/ext/win32ole/win32ole.c
+++ b/ext/win32ole/win32ole.c
@@ -224,6 +224,7 @@ static volatile DWORD g_ole_initialized_key = TLS_OUT_OF_INDEXES;
# define g_ole_initialized_init() (g_ole_initialized_key = TlsAlloc())
# define g_ole_initialized_set(val) TlsSetValue(g_ole_initialized_key, (void*)(val))
#endif
+static BOOL g_uninitialize_hooked = FALSE;
static BOOL g_cp_installed = FALSE;
static BOOL g_lcid_installed = FALSE;
static HINSTANCE ghhctrl = NULL;
@@ -1210,15 +1211,27 @@ ole_raise(HRESULT hr, VALUE ecs, const char *fmt, ...)
void
ole_uninitialize(void)
{
+ if (!g_ole_initialized) return;
OleUninitialize();
g_ole_initialized_set(FALSE);
}
static void
+ole_uninitialize_hook(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass)
+{
+ ole_uninitialize();
+}
+
+static void
ole_initialize(void)
{
HRESULT hr;
+ if(!g_uninitialize_hooked) {
+ rb_add_event_hook(ole_uninitialize_hook, RUBY_EVENT_THREAD_END, Qnil);
+ g_uninitialize_hooked = TRUE;
+ }
+
if(g_ole_initialized == FALSE) {
hr = OleInitialize(NULL);
if(FAILED(hr)) {