From: Bruce Momjian <bruce@momjian.us>
To: Benjamin Wassermann <benny@hegne.de>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #8461: PostgreSQL 9.3 pg_dump heap corruptions
Date: Fri, 14 Feb 2014 23:01:11 -0500
Message-ID: <20140215040111.GA15047@momjian.us> (raw)
In-Reply-To: <1381753906060-5774487.post@n5.nabble.com>
References: <E1VMEdk-00031c-R3@wrigleys.postgresql.org>
<1381753906060-5774487.post@n5.nabble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On Mon, Oct 14, 2013 at 05:31:46AM -0700, Benjamin Wassermann wrote:
> We finally find out why this problem occurs.
>
> PG_dump use some Functions like
> initPQExpBuffer(..)
> from the libpq.dll.
>
> In this function "initPQExpBuffer(...)" are some memory allocated with
> malloc(...).
> (File: "pg_dump.c", line 9366)
>
> After the function is successfully dumped to backup file, there is a
> "free(...)" in Function "dumpFunc" at line 9942 ff.
> ...
> free(funcsig);
> ...
>
> but the PG_dump.exe cant free memory which is allocated by libpq.dll.
>
> To fix this problem the "libpq.dll" need a new function named
> "deletePQCharPointer()"
Actually, there are many places where Windows binaries free memory
allocated by libpq. This is possible because of the way we compile
libpq and the binary. Our PQfreemem() manual page has the details
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().
If the free() was not working for you, my guess is that you had
mismatched flags for libpq and pg_dump compiles.
However, you were right that there was a memory leak in that area of the
code related to how funcfullsig and aggfullsig were conditionally
assigned values, but not freed.
The attached patch fixes this memory leak; not sure if this should be
back-patched.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ Everyone has their own god. +
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:pg_dump.diff (text/x-diff, 3.5K) downloaddiff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.cnew file mode 100644index 458a118..fd0bf4d
*** a/src/bin/pg_dump/pg_dump.c
--- b/src/bin/pg_dump/pg_dump.c
*************** dumpFunc(Archive *fout, FuncInfo *finfo)
*** 9608,9614 ****
PQExpBuffer asPart;
PGresult *res;
char *funcsig; /* identity signature */
! char *funcfullsig; /* full signature */
char *funcsig_tag;
char *proretset;
char *prosrc;
--- 9608,9614 ----
PQExpBuffer asPart;
PGresult *res;
char *funcsig; /* identity signature */
! char *funcfullsig = NULL; /* full signature */
char *funcsig_tag;
char *proretset;
char *prosrc;
*************** dumpFunc(Archive *fout, FuncInfo *finfo)
*** 9916,9928 ****
funcsig = format_function_arguments(finfo, funciargs, false);
}
else
- {
/* pre-8.4, do it ourselves */
funcsig = format_function_arguments_old(fout,
finfo, nallargs, allargtypes,
argmodes, argnames);
- funcfullsig = funcsig;- }
funcsig_tag = format_function_signature(fout, finfo, false);
--- 9916,9925 ----
*************** dumpFunc(Archive *fout, FuncInfo *finfo)
*** 9933,9939 ****
fmtId(finfo->dobj.namespace->dobj.name),
funcsig);
! appendPQExpBuffer(q, "CREATE FUNCTION %s ", funcfullsig);
if (funcresult)
appendPQExpBuffer(q, "RETURNS %s", funcresult);
else
--- 9930,9937 ----
fmtId(finfo->dobj.namespace->dobj.name),
funcsig);
! appendPQExpBuffer(q, "CREATE FUNCTION %s ", funcfullsig ? funcfullsig :
! funcsig);
if (funcresult)
appendPQExpBuffer(q, "RETURNS %s", funcresult);
else
*************** dumpFunc(Archive *fout, FuncInfo *finfo)
*** 10056,10061 ****
--- 10054,10061 ----
destroyPQExpBuffer(labelq);
destroyPQExpBuffer(asPart);
free(funcsig);
+ if (funcfullsig)+ free(funcfullsig);
free(funcsig_tag);
if (allargtypes)
free(allargtypes);
*************** dumpAgg(Archive *fout, AggInfo *agginfo)
*** 11512,11518 ****
PQExpBuffer labelq;
PQExpBuffer details;
char *aggsig; /* identity signature */
! char *aggfullsig; /* full signature */
char *aggsig_tag;
PGresult *res;
int i_aggtransfn;
--- 11512,11518 ----
PQExpBuffer labelq;
PQExpBuffer details;
char *aggsig; /* identity signature */
! char *aggfullsig = NULL; /* full signature */
char *aggsig_tag;
PGresult *res;
int i_aggtransfn;
*************** dumpAgg(Archive *fout, AggInfo *agginfo)
*** 11660,11670 ****
aggsig = format_function_arguments(&agginfo->aggfn, funciargs, true);
}
else
- {
/* pre-8.4, do it ourselves */
aggsig = format_aggregate_signature(agginfo, fout, true);
- aggfullsig = aggsig;- }
aggsig_tag = format_aggregate_signature(agginfo, fout, false);
--- 11660,11667 ----
*************** dumpAgg(Archive *fout, AggInfo *agginfo)
*** 11734,11740 ****
aggsig);
appendPQExpBuffer(q, "CREATE AGGREGATE %s (\n%s\n);\n",
! aggfullsig, details->data);
appendPQExpBuffer(labelq, "AGGREGATE %s", aggsig);
--- 11731,11737 ----
aggsig);
appendPQExpBuffer(q, "CREATE AGGREGATE %s (\n%s\n);\n",
! aggfullsig ? aggfullsig : aggsig, details->data);
appendPQExpBuffer(labelq, "AGGREGATE %s", aggsig);
*************** dumpAgg(Archive *fout, AggInfo *agginfo)
*** 11777,11782 ****
--- 11774,11781 ----
agginfo->aggfn.rolname, agginfo->aggfn.proacl);
free(aggsig);
+ if (aggfullsig)+ free(aggfullsig);
free(aggsig_tag);
PQclear(res);
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: bruce@momjian.us, benny@hegne.de
Subject: Re: BUG #8461: PostgreSQL 9.3 pg_dump heap corruptions
In-Reply-To: <20140215040111.GA15047@momjian.us>
References: <E1VMEdk-00031c-R3@wrigleys.postgresql.org> <1381753906060-5774487.post@n5.nabble.com> <20140215040111.GA15047@momjian.us>
* 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