Re: pgsql: Fix memory leak in pgbench

From: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: Re: pgsql: Fix memory leak in pgbench
Date: 2019-04-10 04:19:11
Message-ID: CAD21AoCXhMNiVLYqNtitzKzE07Z88WzV-2FNFxa9VNZC9WZu1w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

On Wed, Apr 10, 2019 at 2:00 AM Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> wrote:
>
> Fix memory leak in pgbench
>
> Commit 25ee70511ec2 introduced a memory leak in pgbench: some PGresult
> structs were not being freed during error bailout, because we're now
> doing more PQgetResult() calls than previously. Since there's more
> cleanup code outside the discard_response() routine than in it, refactor
> the cleanup code, removing the routine.
>
> This has little effect currently, since we abandon processing after
> hitting errors, but if we ever get further pgbench features (such as
> testing for serializable transactions), it'll matter.
>

This change leads a compiler warning on my machine:

pgbench.c: In function ‘readCommandResponse’:
pgbench.c:2730: warning: ISO C90 forbids mixed declarations and code

@@ -2739,7 +2726,7 @@ readCommandResponse(CState *st, char *varprefix)
while (res != NULL)
{
/* look now at the next result to know whether it is the last */
- PGresult *next_res = PQgetResult(st->con);
+ next_res = PQgetResult(st->con);
bool is_last = (next_res == NULL);

I think we should declare is_last before doing next_res = PQgetResult(st->con).

Attached patch fixes it.

Regards,

--
Masahiko Sawada
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center

Attachment Content-Type Size
pgbench.patch application/octet-stream 494 bytes

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2019-04-10 06:07:38 Re: pgsql: Fix memory leak in pgbench
Previous Message Amit Kapila 2019-04-10 03:32:25 pgsql: Avoid counting transaction stats for parallel worker cooperating