[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] channel: fix setting of channel->flags


Hi,

Attached is a patch which fixes a memory leak via the
'ssh_channel_free' API.  With the patch, I observe that
channels are truly completely free'd in my program.


-Jon
From 09ba6911fe8e494e50f219db2bad10d53356fa57 Mon Sep 17 00:00:00 2001
From: Jon Simons <jon@xxxxxxxxxxxxx>
Date: Mon, 9 Dec 2013 11:24:45 -0800
Subject: [PATCH] channel: fix setting of channel->flags

Fix the setting of 'channel->flags' to use '|='.  Before this
change, one bug symptom can be that channels are never fully
free'd via ssh_channel_free, resulting in memory leaks.
---
 src/channels.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/channels.c b/src/channels.c
index ae977c0..25d3ddb 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -177,7 +177,7 @@ SSH_PACKET_CALLBACK(ssh_packet_channel_open_conf){
       (long unsigned int) channel->remote_maxpacket);
 
   channel->state = SSH_CHANNEL_STATE_OPEN;
-  channel->flags = channel->flags & ~SSH_CHANNEL_FLAG_NOT_BOUND;
+  channel->flags &= ~SSH_CHANNEL_FLAG_NOT_BOUND;
 
   return SSH_PACKET_USED;
 }
@@ -635,7 +635,7 @@ SSH_PACKET_CALLBACK(channel_rcv_close) {
 	      channel,
 	      channel->callbacks->userdata);
 	}
-	channel->flags &= SSH_CHANNEL_FLAG_CLOSED_REMOTE;
+	channel->flags |= SSH_CHANNEL_FLAG_CLOSED_REMOTE;
 	if(channel->flags & SSH_CHANNEL_FLAG_FREED_LOCAL)
 	  ssh_channel_do_free(channel);
 
@@ -1078,7 +1078,7 @@ void ssh_channel_free(ssh_channel channel) {
   if (session->alive && channel->state == SSH_CHANNEL_STATE_OPEN) {
     ssh_channel_close(channel);
   }
-  channel->flags &= SSH_CHANNEL_FLAG_FREED_LOCAL;
+  channel->flags |= SSH_CHANNEL_FLAG_FREED_LOCAL;
 
   /* The idea behind the flags is the following : it is well possible
    * that a client closes a channel that stills exists on the server side.
-- 
1.8.4.21.g992c386


Follow-Ups:
Re: [PATCH] channel: fix setting of channel->flagsAris Adamantiadis <aris@xxxxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org