[omniORB] omni_thread::init_t::~init_t will leak when FreeLibrary is called from a different thread as LoadLibrary

Martin Trappel 0xCDCDCDCD at gmx.at
Wed Jun 4 17:10:04 BST 2008


Hi all!

(omniORB 4.1.2 on Windows XP)

When loading the omnithread33_...dll dynamically with the Win32 function 
LoadLibrary() and later releasing it with FreeLibrary()
... when the two calls are done from different threads the dtor 
omni_thread::init_t::~init_t(void) can't do proper cleanup because 
ThreadLocalStorage is used to store the pointers for the omni_thread 
object. [see omnithread/nt.cc(455)]

What is actually the point of the
[omnithread.h(648)] static omni_thread::init_t omni_thread_init;
object? Why does it use TLS to remember some thread object?

thanks!
Martin


[CODE to repro. on VC8]

#include "stdafx.h"
#include <iostream>

LPCTSTR ominthread_module = 
_T("C:\\Programme\\omniORB-4.1.2\\bin\\x86_win32\\omnithread33_vc8_rtd.dll");

HMODULE g_lib = NULL;

void load_fn(void* p) {
	g_lib = LoadLibrary(ominthread_module);
}

bool terminated = false;
void free_fn(void* p) {
	if(g_lib)
		FreeLibrary(g_lib);
	terminated = true;
}

int _tmain(int argc, _TCHAR* argv[])
{
	//HMODULE lib = LoadLibrary(ominthread_module);
	//if(lib)
	//	FreeLibrary(lib);

	_beginthread(load_fn, 0, NULL);
	Sleep(1000);
	_beginthread(free_fn, 0, NULL);
	Sleep(1000);
	while(!terminated) {
		Sleep(100);
	}

	return 0;
}

using namespace std;

class init_crt {
public:
	init_crt() {
		// Memory Leak Detection of CRT:
		int nFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
		nFlag |= _CRTDBG_LEAK_CHECK_DF;
		_CrtSetDbgFlag(nFlag);

		::_CrtSetBreakAlloc(123);
	}
};

static init_crt init_crt_obj;

[/CODE]



More information about the omniORB-list mailing list