From: Craig Ringer <ringerc@ringerc.id.au>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Alvaro Herrera <alvherre@commandprompt.com>
Cc: Pavel Holec <holec@email.cz>
Cc: Pg Bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #6233: pg_dump hangs with Access Violation C0000005
Date: Wed, 05 Oct 2011 15:24:17 +0800
Message-ID: <4E8C0621.8050108@ringerc.id.au> (raw)
In-Reply-To: <9004.1317787610@sss.pgh.pa.us>
References: <201109282118.p8SLIwYx099581@wwwmaster.postgresql.org>
<4E8422B0.5060404@ringerc.id.au>
<!&!AAAAAAAAAAAYAAAAAAAAAE8q5Jcv4mJImRanr8cGRrPCgAAAEAAAAKoxZCnfy11Bjcdjb1Sap84BAAAAAA==@email.cz>
<4E8A72E3.9080701@ringerc.id.au>
<!&!AAAAAAAAAAAYAAAAAAAAAE8q5Jcv4mJImRanr8cGRrPCgAAAEAAAAEOddjeKN+JAi/9rqv7Z5K0BAAAAAA==@email.cz>
<6027.1317776669@sss.pgh.pa.us>
<1317784584-sup-6771@alvh.no-ip.org>
<9004.1317787610@sss.pgh.pa.us>
Tom Lane wrote:
> However, the flaw in that explanation is that it would basically mean
> pg_dump doesn't work at all on Windows, at least not if you have any
> user-defined functions, and probably some other cases too because there
> seem to be multiple instances of the dubious coding. It's a bit hard to
> believe that nobody's noticed that before.
It's like a double-free - you often get away with it. Some people will
never notice it. Others will crash on it consistently. It'll crash for
some people only on tuesday evenings on full moons, but only if they're
in the southern hemisphere and using a laptop with an exactly 1.8GHz
CPU. Etc.
Add the "interesting" variety of Windows environments and configurations
that exist and it's not surprising to see this sort of issue pop up only
occasionally.
In particular, if your libpq and pg_dump link to the exact same msvcrt
*and* that's a dynamic (dll) runtime not a static runtime, you'll get
away with this. If they link to the same static runtime it'll crash. If
they link to different dynamic runtimes - different versions, different
thread/debug options, etc - then you still might get away with it or
might not, depending on the usual luck associated with double free issues.
> I'm looking at our docs for PQfreemem:
>
> Frees memory allocated by libpq, particularly PQescapeByteaConn,
> PQescapeBytea, PQunescapeBytea, and PQnotifies. It is
> particularly important that this function, rather than free(),
> be used on Microsoft Windows. This is because allocating memory
> in a DLL and releasing it in the application works only if
> multithreaded/single-threaded, release/debug, and static/dynamic
> flags are the same for the DLL and the application. On
> non-Microsoft Windows platforms, this function is the same as
> the standard library function free().
>
> I have no idea how accurate or complete that third sentence is;
> but perhaps the OP is trying to use a libpq.dll that was built
> separately from his pg_dump executable?
Yeah, or if pg_dump is in a different directory to libpq with a
different copy of msvcrt I think you can be bitten by this too.
free()ing RAM malloc'd in a different DLL/EXE is just plain wrong in
Windows anyway. If this wasn't caught by automated tests then tests may
need to be run on -debug builds in future.
--
Craig Ringer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: ringerc@ringerc.id.au, tgl@sss.pgh.pa.us, alvherre@commandprompt.com, holec@email.cz
Subject: Re: BUG #6233: pg_dump hangs with Access Violation C0000005
In-Reply-To: <4E8C0621.8050108@ringerc.id.au>
References: <201109282118.p8SLIwYx099581@wwwmaster.postgresql.org> <4E8422B0.5060404@ringerc.id.au> <!&!AAAAAAAAAAAYAAAAAAAAAE8q5Jcv4mJImRanr8cGRrPCgAAAEAAAAKoxZCnfy11Bjcdjb1Sap84BAAAAAA==@email.cz> <4E8A72E3.9080701@ringerc.id.au> <!&!AAAAAAAAAAAYAAAAAAAAAE8q5Jcv4mJImRanr8cGRrPCgAAAEAAAAEOddjeKN+JAi/9rqv7Z5K0BAAAAAA==@email.cz> <6027.1317776669@sss.pgh.pa.us> <1317784584-sup-6771@alvh.no-ip.org> <9004.1317787610@sss.pgh.pa.us> <4E8C0621.8050108@ringerc.id.au>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox