In tcp_chr_sync_read function, there is a possibility of socket
disconnection during read, then tcp_chr_hup function would clean up
the qio channel pointers(i.e ioc, sioc).

Signed-off-by: Sai Pavan Boddu <sai.pavan.bo...@xilinx.com>
---
Changes for V2:
        Simply guard the  'qio_channel_set_blocking' call to check connection 
status.
        This is a simple fix than v1 and explains much better about the issue.

 chardev/char-socket.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 185fe38..e56b2f0 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -549,7 +549,9 @@ static int tcp_chr_sync_read(Chardev *chr, const uint8_t 
*buf, int len)
 
     qio_channel_set_blocking(s->ioc, true, NULL);
     size = tcp_chr_recv(chr, (void *) buf, len);
-    qio_channel_set_blocking(s->ioc, false, NULL);
+    if (s->state != TCP_CHARDEV_STATE_DISCONNECTED) {
+        qio_channel_set_blocking(s->ioc, false, NULL);
+    }
     if (size == 0) {
         /* connection closed */
         tcp_chr_disconnect(chr);
-- 
2.7.4


Reply via email to