Re: pgsql: Fix memory leak in pgbench - Mailing list pgsql-committers

From Masahiko Sawada
Subject Re: pgsql: Fix memory leak in pgbench
Date
Msg-id CAD21AoCXhMNiVLYqNtitzKzE07Z88WzV-2FNFxa9VNZC9WZu1w@mail.gmail.com
Whole thread Raw
In response to pgsql: Fix memory leak in pgbench  (Alvaro Herrera <alvherre@alvh.no-ip.org>)
Responses Re: pgsql: Fix memory leak in pgbench  (Michael Paquier <michael@paquier.xyz>)
Re: pgsql: Fix memory leak in pgbench  (Fabien COELHO <coelho@cri.ensmp.fr>)
Re: pgsql: Fix memory leak in pgbench  (Alvaro Herrera <alvherre@2ndquadrant.com>)
List pgsql-committers
On Wed, Apr 10, 2019 at 2:00 AM Alvaro Herrera <alvherre@alvh.no-ip.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

pgsql-committers by date:

Previous
From: Amit Kapila
Date:
Subject: pgsql: Avoid counting transaction stats for parallel workercooperating
Next
From: Michael Paquier
Date:
Subject: Re: pgsql: Fix memory leak in pgbench