Re: Memory leak with XLogFileCopy since de768844 (WAL file with .partial)

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Subject: Re: Memory leak with XLogFileCopy since de768844 (WAL file with .partial)
Date: 2015-06-05 03:39:24
Message-ID: CAB7nPqRCFWQPp+jqmiZqt_2CUKD2do_XpgStp1rbZm1A=6hYeg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jun 4, 2015 at 10:40 PM, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:

> On Mon, Jun 1, 2015 at 4:24 PM, Michael Paquier
> <michael(dot)paquier(at)gmail(dot)com> wrote:
> > On Thu, May 28, 2015 at 9:09 PM, Michael Paquier
> > <michael(dot)paquier(at)gmail(dot)com> wrote:
> >> Since commit de768844, XLogFileCopy of xlog.c returns to caller a
> >> pstrdup'd string that can be used afterwards for other things.
> >> XLogFileCopy is used in only one place, and it happens that the result
> >> string is never freed at all, leaking memory.
>
> That seems to be almost harmless because the startup process will exit
> just after calling XLogFileCopy(). No?
>

Yes that's harmless. My point here is correctness, prevention does not hurt
particularly if this code path is used more in the future.

> Also the current error message in case of failure is very C-like:
> > elog(ERROR, "InstallXLogFileSegment should not have failed");
> > I thought that we to use function names in the error messages.
> > Wouldn't something like that be more adapted?
> > "could not copy partial log file" or ""could not copy partial log file
> > into temporary segment file"
>
> Or we can extend InstallXLogFileSegment so that we can give the log level
> to it. When InstallXLogFileSegment is called after XLogFileCopy, we can
> give ERROR as the log level and cause an exception to occur if link() or
> rename() fails in InstallXLogFileSegment.
>

That's neat. Done this way in the attached.
--
Michael

Attachment Content-Type Size
20150605_xlogcopy_fixes_v2.patch text/x-patch 4.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2015-06-05 04:27:06 Re: Re: [COMMITTERS] pgsql: Map basebackup tablespaces using a tablespace_map file
Previous Message Amit Kapila 2015-06-05 03:35:07 Re: Re: [COMMITTERS] pgsql: Map basebackup tablespaces using a tablespace_map file