Avoid calling close(-1) on incomplete stream

This commit is contained in:
Andrea Mazzoleni 2026-05-21 16:27:00 +02:00
parent 212a0ce6d1
commit 21a06e2c56

View file

@ -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 */
}
}
}