Re: BUG #8461: PostgreSQL 9.3 pg_dump heap corruptions

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Benjamin Wassermann <benny(at)hegne(dot)de>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #8461: PostgreSQL 9.3 pg_dump heap corruptions
Date: 2014-02-15 04:01:11
Message-ID: 20140215040111.GA15047@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-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(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +

Attachment Content-Type Size
pg_dump.diff text/x-diff 3.5 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2014-02-15 04:55:25 Re: Bad behaviour on some geometric operations on degenerate polygons
Previous Message pythonesque 2014-02-15 03:55:49 BUG #9227: Error on SELECT ROW OVERLAPS ROW with single ROW argument