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

Re: example of a server


On Wed 25.Apr.12 17:30, Tomasz Mikolajczyk wrote:
Finally, I've running a simple non-blocking ssh server. Valgrind has
found a memory leak in the libssh code. The attachment contains a
patch for 0.5.2 version fixing the leak. I cannot verify whether the
patch is applicable to the latest source code from the repo. The repo
behaves differently and I've got some other errors during the keys
exchange phase (probably).


Hi Tomek,


sorry for the late reply. Do you agree that the attached patch fixes it
and is a better way to fix the issue?

    -- andreas

From b0639185d7cccafbec82662a04d4cb3400f08833 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@xxxxxxxxxxxxxx>
Date: Thu, 14 Jun 2012 11:38:47 +0200
Subject: [PATCH] kex: Fix memory leak.


Signed-off-by: Andreas Schneider <asn@xxxxxxxxxxxxxx>
---
 src/kex.c |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/kex.c b/src/kex.c
index c954e2b..46b074c 100644
--- a/src/kex.c
+++ b/src/kex.c
@@ -368,14 +368,19 @@ int set_kex(ssh_session session){
     const char *wanted;
     enter_function();
     ssh_get_random(client->cookie,16,0);
-    client->methods=malloc(10 * sizeof(char **));
     if (client->methods == NULL) {
-      ssh_set_error(session, SSH_FATAL, "No space left");
-      leave_function();
-      return -1;
+        client->methods = malloc(10 * sizeof(char **));
+        if (client->methods == NULL) {
+            ssh_set_error(session, SSH_FATAL, "No space left");
+            leave_function();
+            return -1;
+        }
+        memset(client->methods, 0, 10 * sizeof(char **));
     }
-    memset(client->methods,0,10*sizeof(char **));
     for (i=0;i<10;i++){
+        if (client->methods[i] != NULL) {
+            SAFE_FREE(client->methods[i]);
+        }
         if(!(wanted=session->wanted_methods[i]))
             wanted=default_methods[i];
         client->methods[i]=ssh_find_matching(server->methods[i],wanted);
-- 
1.7.10.4


Archive administrator: postmaster@lists.cynapses.org