From: Vladimir Sementsov-Ogievskiy Date: Tue, 16 Sep 2025 13:14:01 +0000 (+0300) Subject: chardev: close an fd on failure path X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=30b123acbb89bff8ce7e46f9eef8ad01c2f173c6;p=thirdparty%2Fqemu.git chardev: close an fd on failure path There are at least two failure paths, where we forget to close an fd. Reviewed-by: Daniel P. Berrangé Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Daniel P. Berrangé --- diff --git a/chardev/char-pty.c b/chardev/char-pty.c index fe6bfb043d5..b066f014126 100644 --- a/chardev/char-pty.c +++ b/chardev/char-pty.c @@ -350,6 +350,7 @@ static void char_pty_open(Chardev *chr, close(slave_fd); if (!qemu_set_blocking(master_fd, false, errp)) { + close(master_fd); return; } diff --git a/chardev/char-serial.c b/chardev/char-serial.c index c622d758dbc..4c6ca713eb1 100644 --- a/chardev/char-serial.c +++ b/chardev/char-serial.c @@ -272,6 +272,7 @@ static void qmp_chardev_open_serial(Chardev *chr, return; } if (!qemu_set_blocking(fd, false, errp)) { + close(fd); return; } tty_serial_init(fd, 115200, 'N', 8, 1);