Skip site navigation (1) Skip section navigation (2)

Can a windows DLL have more than one process attached?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-interfaces(at)postgreSQL(dot)org
Subject: Can a windows DLL have more than one process attached?
Date: 2001-11-27 18:31:40
Message-ID: 24767.1006885900@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-interfaces
In reviewing some recent patches I notice the following code added to
src/interfaces/libpq/libpqdll.c:

BOOL WINAPI
DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
        LPVOID lpReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            ...
            if (netmsgModule == NULL)
                netmsgModule = LoadLibraryEx("netmsg.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
            break;
        case DLL_PROCESS_DETACH:
            if (netmsgModule != NULL)
                FreeLibrary(netmsgModule);
            ...
            break;
    }
}

where netmsgModule is

static HINSTANCE netmsgModule = NULL;

This sure looks to me like it will fail miserably if more than one
process can attach to the DLL concurrently: won't the first one to
detach release the netmsg library, breaking access to it for all the
remaining processes?

I don't know enough about Windows to know if there's really a problem
here, but the code looks fishy to me.  I'd expect to need a reference
count.  Comments anyone?

			regards, tom lane

Responses

pgsql-interfaces by date

Next:From: Ross J. ReedstromDate: 2001-11-27 19:01:47
Subject: Re: Can a windows DLL have more than one process attached?
Previous:From: Tom LaneDate: 2001-11-27 16:11:02
Subject: Re: Cant load pgtclsh library into application

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group