Hi, While working on patch [1], I spotted that LZ4Stream_close() doesn’t handle failures cleanly.
If fwrite() fails, it sets the success flag to false, but still proceeds to call LZ4F_compressEnd(). And if LZ4F_compressEnd() fails, it still calls fwrite() without advancing state->bufdata. I don’t think this would lead to an incorrect result, as the success flag remains false, but further compression and write attempts after a failure are unnecessary and may produce additional error messages. Looking at zstd, gzip, and custom-format compression, their close paths don’t have the same issue. Attached is a simple cleanup patch for LZ4Stream_close(). I don’t think it needs to be back-patched. [1] https://www.postgresql.org/message-id/5962B878-C43D-4EBC-9E95-1F945CE5E586%40gmail.com Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/
v1-0001-Avoid-further-compression-and-writes-after-LZ4-cl.patch
Description: Binary data
