From 4d203e8420b0be0a3cd327f0ab9dc688fed54026 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 2 Apr 2009 12:07:06 +0000 Subject: Fix memory leaks. git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@356 7dcaeef0-15fb-0310-b436-a5af3365683c --- libssh/options.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/libssh/options.c b/libssh/options.c index fca875e..71dc749 100644 --- a/libssh/options.c +++ b/libssh/options.c @@ -249,9 +249,7 @@ int ssh_options_set_host(SSH_OPTIONS *opt, const char *hostname){ } p = strchr(h, '@'); - if (opt->host) { - SAFE_FREE(opt->host); - } + SAFE_FREE(opt->host); if (p) { *p = '\0'; @@ -261,9 +259,7 @@ int ssh_options_set_host(SSH_OPTIONS *opt, const char *hostname){ return -1; } - if (opt->username) { - SAFE_FREE(opt->username); - } + SAFE_FREE(opt->username); opt->username = strdup(h); SAFE_FREE(h); if (opt->username == NULL) { @@ -292,10 +288,7 @@ int ssh_options_set_username(SSH_OPTIONS *opt, const char *username) { return -1; } - if (opt->username) { - SAFE_FREE(opt->username); - } - + SAFE_FREE(opt->username); opt->username = strdup(username); if (opt->username == NULL) { return -1; @@ -346,6 +339,7 @@ int ssh_options_set_bind(SSH_OPTIONS *opt, const char *bindaddr, int port) { return -1; } + SAFE_FREE(opt->bindaddr); opt->bindaddr = strdup(bindaddr); if (opt->bindaddr == NULL) { return -1; @@ -378,6 +372,7 @@ int ssh_options_set_ssh_dir(SSH_OPTIONS *opt, const char *dir) { } snprintf(buffer, 1024, dir, ssh_get_user_home_dir()); + SAFE_FREE(opt->ssh_dir); opt->ssh_dir = strdup(buffer); if (opt->ssh_dir == NULL) { return -1; -- cgit