aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Stöneberg <oliverst@online.de>2011-04-26 15:56:00 -0700
committerAndreas Schneider <asn@cryptomilk.org>2011-05-01 19:42:01 +0200
commit2431c7d9250882f83a3b3ce97b7cb0dd04c48344 (patch)
tree0275d20034e96be820fa14885dfd384dd0b05dc0
parentfc9c61714f4fc509320843bd0edd1cddbdd6943d (diff)
downloadlibssh-2431c7d9250882f83a3b3ce97b7cb0dd04c48344.tar.gz
libssh-2431c7d9250882f83a3b3ce97b7cb0dd04c48344.tar.xz
libssh-2431c7d9250882f83a3b3ce97b7cb0dd04c48344.zip
examples: Fixed memory leak in samplessh when using commands.
(cherry picked from commit c3849a3cfd4bb298c255c41bf2cbc5592e893d17)
-rw-r--r--examples/sample.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/examples/sample.c b/examples/sample.c
index c7fec6c8..547fd184 100644
--- a/examples/sample.c
+++ b/examples/sample.c
@@ -431,8 +431,11 @@ static void batch_shell(ssh_session session){
ssh_channel channel;
char buffer[1024];
int i,s=0;
- for(i=0;i<MAXCMD && cmds[i];++i)
+ for(i=0;i<MAXCMD && cmds[i];++i) {
s+=snprintf(buffer+s,sizeof(buffer)-s,"%s ",cmds[i]);
+ free(cmds[i]);
+ cmds[i] = NULL;
+ }
channel=ssh_channel_new(session);
ssh_channel_open_session(channel);
if(ssh_channel_request_exec(channel,buffer)){