From bf3635fd75c9afd736c826b1cc89e3d07afad887 Mon Sep 17 00:00:00 2001 From: YongDo-Hyun Date: Sat, 27 Dec 2025 16:38:59 +0300 Subject: fix: improve exception handling in ozlibstream::close method to prevent masking errors Signed-off-by: YongDo-Hyun --- src/io/ozlibstream.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/io/ozlibstream.cpp b/src/io/ozlibstream.cpp index d1cb25dac0..c62f58dace 100644 --- a/src/io/ozlibstream.cpp +++ b/src/io/ozlibstream.cpp @@ -97,30 +97,31 @@ void ozlibstream::close() { // Capture the exception mask so we can restore it if close() fails. std::ios_base::iostate old_ex = exceptions(); - bool close_failed = false; try { buf.close(); + return; } catch(...) { - close_failed = true; + // fall through to mark the stream as bad } - if(!close_failed) - return; // Setting the stream state while exceptions are enabled may cause // `setstate` to throw an `ios_base::failure` which would replace // the original exception. Temporarily disable exceptions on this // stream, set the `badbit`, then restore the exception mask. - std::ios_base::iostate old_ex = exceptions(); exceptions(std::ios_base::goodbit); setstate(std::ios_base::badbit); - try { - exceptions(old_ex); - } catch (...) { - // If anything unexpected happens while restoring the exception mask, - // swallow it — we don't want this to throw here. + try + { + exceptions(old_ex); + } + catch(...) + { + // If anything unexpected happens while restoring the exception mask, + // swallow it — we don't want this to throw here. } - } } + +} // namespace zlib -- cgit 0.0.5-2-1-g0f52