sleeptime = CalculateCopyStreamSleeptime(now, stream->standby_message_timeout,
last_status);
+ /* Done with any prior message */
+ PQfreemem(copybuf);
+ copybuf = NULL;
+
r = CopyStreamReceive(conn, sleeptime, stream->stop_socket, ©buf);
while (r != 0)
{
if (res == NULL)
goto error;
- else
- return res;
+ PQfreemem(copybuf);
+ return res;
}
/* Check the message type. */
goto error;
}
+ /* Done with that message */
+ PQfreemem(copybuf);
+ copybuf = NULL;
+
/*
* Process the received data, and any subsequent data we can read
* without blocking.
* maximum of 'timeout' ms.
*
* If data was received, returns the length of the data. *buffer is set to
- * point to a buffer holding the received message. The buffer is only valid
- * until the next CopyStreamReceive call.
+ * point to a buffer holding the received message. The caller must eventually
+ * free the buffer with PQfreemem().
*
* Returns 0 if no data was available within timeout, or if wait was
* interrupted by signal or stop_socket input.
char *copybuf = NULL;
int rawlen;
- PQfreemem(*buffer);
- *buffer = NULL;
+ /* Caller should have cleared any prior buffer */
+ Assert(*buffer == NULL);
/* Try to receive a CopyData message */
rawlen = PQgetCopyData(conn, ©buf, 1);
}
still_sending = false;
}
- PQfreemem(copybuf);
*stoppos = blockpos;
return res;
}