Free PQresult on error in pg_receivexlog.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 12 May 2014 07:17:40 +0000 (10:17 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 12 May 2014 07:59:08 +0000 (10:59 +0300)
The leak is fairly small and rare, but a leak nevertheless.

Per Coverity report. Backpatch to 9.2, where pg_receivexlog was added.
pg_basebackup shares the code, but it always exits on error, so there is
no real leak.

src/bin/pg_basebackup/receivelog.c

index aca1a9e8b1a764da47b58b5650f2b4c811b41ad5..ded9b70dc2180778b82ae44058eb20e161fb0a87 100644 (file)
@@ -912,6 +912,7 @@ HandleCopyStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline,
                if (!close_walfile(basedir, partial_suffix))
                {
                    /* Error message written in close_walfile() */
+                   PQclear(res);
                    goto error;
                }
                if (PQresultStatus(res) == PGRES_COPY_IN)
@@ -921,6 +922,7 @@ HandleCopyStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline,
                        fprintf(stderr,
                                _("%s: could not send copy-end packet: %s"),
                                progname, PQerrorMessage(conn));
+                       PQclear(res);
                        goto error;
                    }
                    res = PQgetResult(conn);