From a78784536c023b6ec6476c0031c84f0f5bc1e1d4 Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <dgustafsson@postgresql.org>
Date: Wed, 25 Jun 2025 15:08:12 +0200
Subject: [PATCH v5 5/6] pg_dump compression API: LZ4Stream_init

Make sure to not switch to state inited until we know that initialization
succeeded and reset errno just in case.
---
 src/bin/pg_dump/compress_lz4.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/bin/pg_dump/compress_lz4.c b/src/bin/pg_dump/compress_lz4.c
index a34c1119f22..82d6c0cd55d 100644
--- a/src/bin/pg_dump/compress_lz4.c
+++ b/src/bin/pg_dump/compress_lz4.c
@@ -359,7 +359,6 @@ LZ4Stream_init(LZ4State *state, int size, bool compressing)
 		return true;
 
 	state->compressing = compressing;
-	state->inited = true;
 
 	/* When compressing, write LZ4 header to the output stream. */
 	if (state->compressing)
@@ -368,6 +367,7 @@ LZ4Stream_init(LZ4State *state, int size, bool compressing)
 		if (!LZ4State_compression_init(state))
 			return false;
 
+		errno = 0;
 		if (fwrite(state->buffer, 1, state->compressedlen, state->fp) != state->compressedlen)
 		{
 			errno = (errno) ? errno : ENOSPC;
@@ -391,6 +391,7 @@ LZ4Stream_init(LZ4State *state, int size, bool compressing)
 		state->overflowlen = 0;
 	}
 
+	state->inited = true;
 	return true;
 }
 
-- 
2.39.3 (Apple Git-146)

