From 4ccac92d08f22ef0f8df29ea6bd9d5e77bf1d246 Mon Sep 17 00:00:00 2001
From: Fujii Masao <fujii@postgresql.org>
Date: Fri, 4 Jul 2014 19:48:38 +0900
Subject: [PATCH] Fix double-free bug of WAL streaming buffer in
 pg_receivexlog.

This bug was introduced while refactoring in commit 74cbe96.
---
 src/bin/pg_basebackup/receivelog.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c
index 4aa35da2fc..97a078526a 100644
--- a/src/bin/pg_basebackup/receivelog.c
+++ b/src/bin/pg_basebackup/receivelog.c
@@ -1079,12 +1079,11 @@ CopyStreamPoll(PGconn *conn, long timeout_ms)
 static int
 CopyStreamReceive(PGconn *conn, long timeout, char **buffer)
 {
-	static char	   *copybuf = NULL;
+	char	   *copybuf = NULL;
 	int			rawlen;
 
-	if (copybuf != NULL)
-		PQfreemem(copybuf);
-	copybuf = NULL;
+	if (*buffer != NULL)
+		PQfreemem(*buffer);
 	*buffer = NULL;
 
 	/* Try to receive a CopyData message */
-- 
2.49.0