]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
chardev/char-file: fix failure path
authorVladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Tue, 14 Oct 2025 14:50:28 +0000 (17:50 +0300)
committerMarc-André Lureau <marcandre.lureau@redhat.com>
Tue, 25 Nov 2025 07:09:07 +0000 (11:09 +0400)
'in' will be -1 when file->in is unset. Let's not try to close
invalid fd.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Coverity: CID 1630444
Fixes: 69620c091d62f "chardev: qemu_chr_open_fd(): add errp"
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20251014145029.949285-1-vsementsov@yandex-team.ru>

chardev/char-file.c

index 89e9cb849c840c4f7e300cfd38e702c69d4c590c..1f7adf592ffc333c3d3301d05b160f11d8b082fa 100644 (file)
@@ -94,7 +94,9 @@ static void qmp_chardev_open_file(Chardev *chr,
 
     if (!qemu_chr_open_fd(chr, in, out, errp)) {
         qemu_close(out);
-        qemu_close(in);
+        if (in >= 0) {
+            qemu_close(in);
+        }
         return;
     }
 #endif