From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51071) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbUK5-0001DR-25 for qemu-devel@nongnu.org; Fri, 06 Jul 2018 13:15:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fbUK3-0000mF-Qz for qemu-devel@nongnu.org; Fri, 06 Jul 2018 13:15:09 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:52029) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fbUK3-0000lw-Ju for qemu-devel@nongnu.org; Fri, 06 Jul 2018 13:15:07 -0400 Received: by mail-wm0-x242.google.com with SMTP id s12-v6so15581981wmc.1 for ; Fri, 06 Jul 2018 10:15:07 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 6 Jul 2018 19:14:25 +0200 Message-Id: <1530897268-22932-6-git-send-email-pbonzini@redhat.com> In-Reply-To: <1530897268-22932-1-git-send-email-pbonzini@redhat.com> References: <1530897268-22932-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PULL 5/8] qemu-char: check errno together with ret < 0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: "xinhua.Cao" From: "xinhua.Cao" 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 17519ec..efbad6e 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; -- 1.8.3.1