From: Jan K. <jan...@my...> - 2007-03-08 10:13:37
|
Doug MacEachern wrote: > On Mar 7, 2007, at 3:43 PM, Doug MacEachern wrote: > ... >> >> I'll re-consider use of goto/error in the future, perhaps starting with >> cleanup of of the kdll handles :) >> > I had forgotten about this, but here's the reason there's no > FreeLibrary(kdll): > > "The GetModuleHandle function returns a handle to a mapped module > without incrementing its reference count. Therefore, use care when > passing the handle to the FreeLibrary function, because doing so can > cause a DLL module to be unmapped prematurely." > > See: http://msdn2.microsoft.com/en-us/library/ms683199.aspx I see 3 ways to handle this: 1. open a extra handle in the init-function to make sure the ref-count never becomes zero 2. get the handle once in the init function and close in shutdown 3. get the handle once in the get_remote_proc_env function and close on sigar-shutdown. if (!sigar->kdll_...) { sigar->kdll_... = GetModuleHandle(...); } sigar_shutdown() { if (sigar->kdll_...) CloseHandle(sigar->kdll...); ... } That way they are only open once and the sigar_shutdown() can cleanup at the end. Jan -- Jan Kneschke, MySQL GmbH, Radlkoferstr. 2, D-81373 München Geschäftsführer: Hans von Bell, Kaj Arnö - HRB München 162140 |