mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 02:38:09 +09:00
options: Avoid memory leaks on allocation failures
When allocation during tilde expansion fails, libssh could leak a memory. Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
@@ -1985,10 +1985,10 @@ int ssh_options_apply(ssh_session session)
|
|||||||
* it with ssh expansion of ssh escape characters.
|
* it with ssh expansion of ssh escape characters.
|
||||||
*/
|
*/
|
||||||
tmp = ssh_path_expand_escape(session, id);
|
tmp = ssh_path_expand_escape(session, id);
|
||||||
|
free(id);
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
free(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* use append to keep the order at first call and use prepend
|
/* use append to keep the order at first call and use prepend
|
||||||
@@ -1999,6 +1999,7 @@ int ssh_options_apply(ssh_session session)
|
|||||||
rc = ssh_list_append(session->opts.identity, tmp);
|
rc = ssh_list_append(session->opts.identity, tmp);
|
||||||
}
|
}
|
||||||
if (rc != SSH_OK) {
|
if (rc != SSH_OK) {
|
||||||
|
free(tmp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2010,13 +2011,14 @@ int ssh_options_apply(ssh_session session)
|
|||||||
char *id = tmp;
|
char *id = tmp;
|
||||||
|
|
||||||
tmp = ssh_path_expand_escape(session, id);
|
tmp = ssh_path_expand_escape(session, id);
|
||||||
|
free(id);
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
free(id);
|
|
||||||
|
|
||||||
rc = ssh_list_append(session->opts.certificate, tmp);
|
rc = ssh_list_append(session->opts.certificate, tmp);
|
||||||
if (rc != SSH_OK) {
|
if (rc != SSH_OK) {
|
||||||
|
free(tmp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user