>From dfb0c9bde2727adbb7474d5aaef812b2debd8d00 Mon Sep 17 00:00:00 2001
From: liuzl <xie...@gmail.com>
Date: Mon, 19 Sep 2011 09:45:33 +0800
Subject: [PATCH] avoid NULL loop in sftp_read()

modify the goto conditions in sftp_read() to avoid NULL loop

Signed-off-by: liuzl <xie...@gmail.com>
---
 src/sftp.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/src/sftp.c b/src/sftp.c
index fc80bac..f4b8d5f 100644
--- a/src/sftp.c
+++ b/src/sftp.c
@@ -1110,8 +1110,14 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE *
handle, char *buffer,
     /* if we previously aborted a channel_write due to EAGAIN, we must
        continue that writing so that we don't risk trying to send another
        channel_write here to enlarge the receive window */
-    if(sftp->read_state == libssh2_NB_state_sent)
+    if(sftp->read_state == libssh2_NB_state_sent &&
+            _libssh2_list_first(&handle->packet_list) != NULL) {
+        /* If we previously set the read_state to libssh2_NB_state_sent
+        due to EAGAIN, but the caller canceled subsequent request(by close
+        handle or seek), then we will get a NULL loop in the next call,
+        give a judgement here to avoid this. */
         goto send_read_requests;
+    }

     /* We allow a number of bytes being requested at any given time without
        having been acked - until we reach EOF. */
-- 
1.7.4.msysgit.0
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

Reply via email to