summaryrefslogtreecommitdiffstats
path: root/src/socket.c
diff options
context:
space:
mode:
authormilo <milo@r0ot.me>2011-04-20 04:13:01 +0200
committermilo <milo@r0ot.me>2011-05-02 17:02:25 +0200
commit7d2064c2894fc298cc8923cae657200900b032e5 (patch)
treea7b2f42a09b6cb7cc7754c203cf3704fc2fb2331 /src/socket.c
parenteb5fedb6851acd12c8b0b5b533ec38dfea927600 (diff)
downloadlibssh-7d2064c2894fc298cc8923cae657200900b032e5.tar.gz
libssh-7d2064c2894fc298cc8923cae657200900b032e5.tar.xz
libssh-7d2064c2894fc298cc8923cae657200900b032e5.zip
[socket] fix a segfault at disconnect
(cherry picked from commit 56394917b15e41603c641c22a4e29c33b096d673)
Diffstat (limited to 'src/socket.c')
-rw-r--r--src/socket.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/socket.c b/src/socket.c
index 6b15e6d..f3da428 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -246,8 +246,9 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd, int r
s->read_wontblock=1;
r=ssh_socket_unbuffered_read(s,buffer,sizeof(buffer));
if(r<0){
- if(p != NULL)
- ssh_poll_set_events(p,ssh_poll_get_events(p) & ~POLLIN);
+ if(p != NULL) {
+ ssh_poll_remove_events(p, POLLIN);
+ }
if(s->callbacks && s->callbacks->exception){
s->callbacks->exception(
SSH_SOCKET_EXCEPTION_ERROR,
@@ -255,7 +256,12 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd, int r
}
}
if(r==0){
- ssh_poll_set_events(p,ssh_poll_get_events(p) & ~POLLIN);
+ if(p != NULL) {
+ ssh_poll_remove_events(p, POLLIN);
+ }
+ if(p != NULL) {
+ ssh_poll_remove_events(p, POLLIN);
+ }
if(s->callbacks && s->callbacks->exception){
s->callbacks->exception(
SSH_SOCKET_EXCEPTION_EOF,
@@ -270,6 +276,9 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd, int r
buffer_get_rest_len(s->in_buffer),
s->callbacks->userdata);
buffer_pass_bytes(s->in_buffer,r);
+ /* p may have been freed, so don't use it
+ * anymore in this function */
+ p = NULL;
}
}
}
@@ -290,7 +299,9 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd, int r
}
/* So, we can write data */
s->write_wontblock=1;
- ssh_poll_remove_events(p,POLLOUT);
+ if(p != NULL) {
+ ssh_poll_remove_events(p, POLLOUT);
+ }
/* If buffered data is pending, write it */
if(buffer_get_rest_len(s->out_buffer) > 0){