RE: [INTERNALS-WIN] FreeLibrary(GetModuleHand le(…))?

[email protected] (Anatol Belski) Mon, 11 Jun 2018 07:33:01 +0000
Newsgroups php.internals.win
Message-ID <AM6PR0502MB38481790F12DECB1344AAD56BA780@AM6PR0502MB3848.eurprd05.prod.outlook.com>
Hi Christoph,

> -----Original Message-----
> From: Christoph M. Becker <[email protected]>
> Sent: Monday, June 11, 2018 1:34 AM
> To: internals-win <[email protected]>
> Subject: [INTERNALS-WIN] FreeLibrary(GetModuleHandle(…))?
> 
> Hi everybody!
> 
> Due to <https://bugs.php.net/76443>, I've noticed a few occurrences where
> FreeLibrary() is called on a handle retrieved by GetModuleHandle().  According to
> the documentation of GetModuleHandle()[1], these appear to be wrong, since
> the docs state:
> 
> | Retrieves a module handle for the specified module. The module must
> | have been loaded by the calling process.
> 
> and
> 
> | Therefore, do not pass a handle returned by GetModuleHandle to the
> | FreeLibrary function.
> 
> Could one of the Windows specialists please review these cases, please?
> 
FreeModule is not be used on a handle retrieved by GetModuleHandle(), so we definitely have to do with a bug here. Especially in the thread safe build it's dangerous. On different Windows versions the system loader differs in its smartness, so it can handle it a different way. If no one beats me to it, I'll be checking through other usages, also in the lower branches, today or tomorrow.

Regards

Anatol