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

how to free memory allocated for keys


Hi!
Briefly: how to free memory allocated for keys correctly ?
In detail:
I tried to read the documents libssh_tutor_guided_tour, api.libssh.org carefully
also I peek the source code of the library libssh sometimes :)
I know that after ssh_new () it is necessary to make ssh_free ()
I know that after ssh_connect() it is necessary to make ssh_disconnect()
and do it in this order:
1) ssh_new()
2) ssh_connect()
3) ssh_disconnect()
4) ssh_free()
But I do not understand when I should do ssh_key_free () ?
Can I do this just one time ssh_pki_import_pubkey_file() and
ssh_pki_import_privkey_file() at the beginning of the program ?
Can i NOT do it every time ssh_pki_import_pubkey_file() and
ssh_pki_import_privkey_file() after ssh_new() ?Should I worry about
ssh_key_free() will be call somewhere inside libssh ?
if you will do this kind of infinite loop:
for(;;){
if( !ssh_new() )
{
ssh_free();
continue;
}
if( !ssh_connect() )
{
ssh_disconnect()
ssh_free()
continue;
}
ssh_pki_import_pubkey_file(filename, ssh_key * pkey) /* if ssh_connect() will be
unsuccessfull then memory leak will be happened */
ssh_pki_import_privkey_file(filename, NULL, NULL, NULL, ssh_key * pkey) /* if
ssh_connect() will be unsuccessfull then memory leak will be happened */
ssh_userauth_try_publickey()
ssh_userauth_publickey()
ssh_disconnect()
ssh_key_free()
ssh_free()
}
--
Andrey Seredin

Archive administrator: postmaster@lists.cynapses.org