diff --git a/include/libssh/misc.h b/include/libssh/misc.h index c340b473..08f8af7b 100644 --- a/include/libssh/misc.h +++ b/include/libssh/misc.h @@ -92,6 +92,8 @@ struct ssh_jump_info_struct { int port; }; +void ssh_jump_info_free(struct ssh_jump_info_struct *jump); + struct ssh_timestamp { long seconds; long useconds; diff --git a/src/config.c b/src/config.c index 1e76457d..e3f52c45 100644 --- a/src/config.c +++ b/src/config.c @@ -656,7 +656,6 @@ ssh_config_parse_proxy_jump(ssh_session session, const char *s, bool do_parsing) false); if (rv != SSH_OK) { ssh_set_error_invalid(session); - SAFE_FREE(jump_host); goto out; } /* Leave the port at 0 when it is not given, so that the jump @@ -671,7 +670,6 @@ ssh_config_parse_proxy_jump(ssh_session session, const char *s, bool do_parsing) session->opts.proxy_jumps = ssh_list_new(); if (session->opts.proxy_jumps == NULL) { ssh_set_error_oom(session); - SAFE_FREE(jump_host); rv = SSH_ERROR; goto out; } @@ -681,9 +679,10 @@ ssh_config_parse_proxy_jump(ssh_session session, const char *s, bool do_parsing) rv = ssh_list_prepend(session->opts.proxy_jumps, jump_host); if (rv != SSH_OK) { ssh_set_error_oom(session); - SAFE_FREE(jump_host); goto out; } + /* moved ownership to the ssh_list */ + jump_host = NULL; } else if (parse_entry) { /* We actually care only about the first item */ rv = ssh_config_parse_uri(cp, @@ -752,6 +751,7 @@ out: if (rv != SSH_OK) { ssh_proxyjumps_free(session->opts.proxy_jumps); } + ssh_jump_info_free(jump_host); SAFE_FREE(username); SAFE_FREE(hostname); SAFE_FREE(port); @@ -1814,7 +1814,7 @@ static int ssh_config_parse_line_internal(ssh_session session, CHECK_COND_OR_FAIL(1, "Invalid data limit"); break; } - + val = (double)ll; if (*endp == '.') { endp++; diff --git a/src/misc.c b/src/misc.c index 792b0141..52ee9153 100644 --- a/src/misc.c +++ b/src/misc.c @@ -2646,6 +2646,21 @@ int ssh_check_username_syntax(const char *username) return SSH_OK; } +/* @brief Free the ssh_jump_info_struct and its members. + * + * @param[in] jump Proxy jump info structure to free (may be NULL) + */ +void ssh_jump_info_free(struct ssh_jump_info_struct *jump) +{ + if (jump == NULL) { + return; + } + + SAFE_FREE(jump->hostname); + SAFE_FREE(jump->username); + SAFE_FREE(jump); +} + /** * @brief Free proxy jump list * @@ -2664,9 +2679,7 @@ ssh_proxyjumps_free(struct ssh_list *proxy_jump_list) jump != NULL; jump = ssh_list_pop_head(struct ssh_jump_info_struct *, proxy_jump_list)) { - SAFE_FREE(jump->hostname); - SAFE_FREE(jump->username); - SAFE_FREE(jump); + ssh_jump_info_free(jump); } }