From c28ad814d0a7a5279a31feea91aaa83762270ff3 Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Wed, 5 Feb 2014 08:07:45 +0100 Subject: [PATCH] knownhosts: resolve leaks found by coverity --- src/kex.c | 4 +++- src/known_hosts.c | 13 +++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/kex.c b/src/kex.c index 6433ee6f..e1e3697c 100644 --- a/src/kex.c +++ b/src/kex.c @@ -390,8 +390,10 @@ static char *ssh_client_select_hostkeys(ssh_session session){ int needcoma=0; methods = ssh_knownhosts_algorithms(session); - if (methods == NULL || methods[0] == NULL) + if (methods == NULL || methods[0] == NULL){ + SAFE_FREE(methods); return NULL; + } for (i=0;preferred_hostkeys[i] != NULL; ++i){ for (j=0; methods[j] != NULL; ++j){ diff --git a/src/known_hosts.c b/src/known_hosts.c index 57cd0e75..8c05c8de 100644 --- a/src/known_hosts.c +++ b/src/known_hosts.c @@ -678,24 +678,21 @@ char **ssh_knownhosts_algorithms(ssh_session session) { } if (session->opts.host == NULL) { - return 0; + return NULL; } host = ssh_lowercase(session->opts.host); hostport = ssh_hostport(host, session->opts.port); - if (host == NULL || hostport == NULL) { + array = malloc(sizeof(char *) * KNOWNHOSTS_MAXTYPES); + + if (host == NULL || hostport == NULL || array == NULL) { ssh_set_error_oom(session); SAFE_FREE(host); SAFE_FREE(hostport); + SAFE_FREE(array); return NULL; } - array = malloc(sizeof(char *) * KNOWNHOSTS_MAXTYPES); - if (array==NULL){ - ssh_set_error_oom(session); - return NULL; - } - do { tokens = ssh_get_knownhost_line(&file, session->opts.knownhosts, &type);