[PATCH] bzip2recover: bsClose bsWr on early EOF

Mark Wielaard mark@klomp.org
Thu May 28 17:31:28 GMT 2026


When getting an early EOF bsWr is never closed so any buffered output
is leaked and never flushed out to the file.
---
 bzip2recover.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/bzip2recover.c b/bzip2recover.c
index 6144284e6c04..e6c3dff3f950 100644
--- a/bzip2recover.c
+++ b/bzip2recover.c
@@ -441,7 +441,12 @@ Int32 main ( Int32 argc, Char** argv )
    wrBlock = 0;
    while (True) {
       b = bsGetBit(bsIn);
-      if (b == 2) break;
+      if (b == 2) {
+         if (outFile != NULL) {
+            bsClose(bsWr);
+         }
+         break;
+      }
       buffHi = (buffHi << 1) | (buffLo >> 31);
       buffLo = (buffLo << 1) | (b & 1);
       if (bitsRead == 47+rbStart[wrBlock]) 
-- 
2.54.0



More information about the Bzip2-devel mailing list