[PATHC] Fix minor memory leak in pg_basebackup

Zhang, Jie <zhangjie2@cn.fujitsu.com>

From: "Zhang, Jie" <zhangjie2@cn.fujitsu.com>
To: "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Cc: "Zhang, Jie" <zhangjie2@cn.fujitsu.com>
Date: 2020-04-15T10:06:52Z
Lists: pgsql-hackers

Attachments

Hi all

In some cases , PGresult is not cleared.

File: src\bin\pg_basebackup\streamutil.c

bool
RetrieveWalSegSize(PGconn *conn)
{
	PGresult   *res;
......
	res = PQexec(conn, "SHOW wal_segment_size");
	if (PQresultStatus(res) != PGRES_TUPLES_OK)
	{
		pg_log_error("could not send replication command \"%s\": %s",
					 "SHOW wal_segment_size", PQerrorMessage(conn));

		PQclear(res); // *** res  is cleared  ***
		return false;
	}
......
	/* fetch xlog value and unit from the result */
	if (sscanf(PQgetvalue(res, 0, 0), "%d%s", &xlog_val, xlog_unit) != 2)
	{
		pg_log_error("WAL segment size could not be parsed");
		return false;    // *** res  is not cleared  ***
	}
......
	if (!IsValidWalSegSize(WalSegSz))
	{
		pg_log_error(ngettext("WAL segment size must be a power of two between 1 MB and 1 GB, but the remote server reported a value of %d byte",
							  "WAL segment size must be a power of two between 1 MB and 1 GB, but the remote server reported a value of %d bytes",
							  WalSegSz),
					 WalSegSz);
		return false;   ;    // *** res  is not cleared  ***
	}
......


Here is a patch.

Best Regards!





Commits

  1. Fix minor memory leak in pg_basebackup and pg_receivewal