*** a/src/bin/pg_basebackup/receivelog.c
--- b/src/bin/pg_basebackup/receivelog.c
***************
*** 628,633 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline,
--- 628,634 ----
  				fprintf(stderr,
  				   _("%s: unexpected termination of replication stream: %s"),
  						progname, PQresultErrorMessage(res));
+ 				PQclear(res);
  				goto error;
  			}
  			PQclear(res);
***************
*** 642,647 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline,
--- 643,650 ----
  		}
  		else if (PQresultStatus(res) == PGRES_COMMAND_OK)
  		{
+ 			PQclear(res);
+ 
  			/*
  			 * End of replication (ie. controlled shut down of the server).
  			 *
***************
*** 663,668 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline,
--- 666,672 ----
  			fprintf(stderr,
  					_("%s: unexpected termination of replication stream: %s"),
  					progname, PQresultErrorMessage(res));
+ 			PQclear(res);
  			goto error;
  		}
  	}
