From: Doug M. <do...@hy...> - 2007-03-08 20:23:05
|
I was pointing out "without incrementing its reference count". I =20 don't think CloseHandle() has any effect on the handle returned by =20 GetModuleHandle(), does it? On Mar 8, 2007, at 2:13 AM, Jan Kneschke wrote: > 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 =20 > 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 =20 > close on > sigar-shutdown. > > if (!sigar->kdll_...) { > sigar->kdll_... =3D GetModuleHandle(...); > } > > sigar_shutdown() { > if (sigar->kdll_...) CloseHandle(sigar->kdll...); > ... > } > > That way they are only open once and the sigar_shutdown() can =20 > cleanup at > the end. > > Jan > -- > Jan Kneschke, MySQL GmbH, Radlkoferstr. 2, D-81373 M=FCnchen > Gesch=E4ftsf=FChrer: Hans von Bell, Kaj Arn=F6 - HRB M=FCnchen 162140 > > |