From 81e34930ce2b605ce9dbb54a7b846379cbb1b811 Mon Sep 17 00:00:00 2001 From: "xinhua.Cao" Date: Wed, 4 Jul 2018 11:36:42 +0800 Subject: [PATCH] qemu-char: check errno together with ret < 0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit In the tcp_chr_write function, we checked errno, but errno was not reset before a read or write operation. Therefore, this check of errno's actions is often incorrect after EAGAIN has occurred. we need check errno together with ret < 0. Signed-off-by: xinhua.Cao Message-Id: <20180704033642.15996-1-caoxinhua@huawei.com> Reviewed-by: Marc-André Lureau Reviewed-by: Daniel P. Berrangé Fixes: 9fc53a10f81d3a9027b23fa810147d21be29e614 Signed-off-by: Paolo Bonzini --- chardev/char-socket.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 17519ec589..efbad6ee7c 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -134,8 +134,11 @@ static int tcp_chr_write(Chardev *chr, const uint8_t *buf, int len) s->write_msgfds, s->write_msgfds_num); - /* free the written msgfds in any cases other than errno==EAGAIN */ - if (EAGAIN != errno && s->write_msgfds_num) { + /* free the written msgfds in any cases + * other than ret < 0 && errno == EAGAIN + */ + if (!(ret < 0 && EAGAIN == errno) + && s->write_msgfds_num) { g_free(s->write_msgfds); s->write_msgfds = 0; s->write_msgfds_num = 0; -- 2.11.0