From bfaa60890bbeba507366285cb1f43aeaa1c4e5d9 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 21 May 2026 16:27:00 +0200 Subject: [PATCH] Avoid calling close(-1) on incomplete stream --- cmdline/stream.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cmdline/stream.c b/cmdline/stream.c index 83116599..7e19a393 100644 --- a/cmdline/stream.c +++ b/cmdline/stream.c @@ -183,10 +183,13 @@ int sclose(STREAM* s) } for (i = 0; i < s->handle_size; ++i) { - if (close(s->handle[i].f) != 0) { - /* LCOV_EXCL_START */ - fail = 1; - /* LCOV_EXCL_STOP */ + /* if open failed, there is nothing to close */ + if (s->handle[i].f != -1) { + if (close(s->handle[i].f) != 0) { + /* LCOV_EXCL_START */ + fail = 1; + /* LCOV_EXCL_STOP */ + } } }