"Ross J. Reedstrom" <reedstrm@rice.edu> writes:
> The FreeLibrary function decrements the reference count of the
> loaded dynamic-link library (DLL) module.
> So it's doing the reference counting.
Yeah, but what increments the reference count? I could believe the code
was okay if it did LoadLibraryEx (which presumably increments the count)
on *every* attach call, but it does that only once, whereas it'll do
FreeLibrary on each detach.
However, we may have worse problems.
> It is not safe to call FreeLibrary or LoadLibraryEx from DllMain.
This looks ugly, although I'm not sure if it's really a problem for us.
I don't see how our pointing to netmsg could create a dependency loop.
I'm also wondering just exactly how Microsoft expects one DLL to be able
to safely reference another, if it's unsafe to call FreeLibrary during
detach --- what else are you supposed to do, leak the reference count?
If this is a problem, a possible answer is not to try to cache the
netmsg reference at all, but just to load and unload that DLL at the
single point where it's used. Since we only use it to translate
socket error reports, there's probably no big performance penalty
involved to do it that way.
regards, tom lane