Improve free functions of the keyfiles.

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@389 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Andreas Schneider
2009-04-04 14:38:39 +00:00
parent 226e48b4b7
commit f7959bd5eb

View File

@@ -660,23 +660,20 @@ PRIVATE_KEY *_privatekey_from_file(void *session,char *filename,int type){
/** \brief deallocate a private key /** \brief deallocate a private key
* \param prv a PRIVATE_KEY object * \param prv a PRIVATE_KEY object
*/ */
void private_key_free(PRIVATE_KEY *prv){ void private_key_free(PRIVATE_KEY *prv) {
if (prv == NULL) { if (prv == NULL) {
return; return;
} }
#ifdef HAVE_LIBGCRYPT #ifdef HAVE_LIBGCRYPT
if(prv->dsa_priv) gcry_sexp_release(prv->dsa_priv);
gcry_sexp_release(prv->dsa_priv); gcry_sexp_release(prv->rsa_priv);
if(prv->rsa_priv)
gcry_sexp_release(prv->rsa_priv);
#elif defined HAVE_LIBCRYPTO #elif defined HAVE_LIBCRYPTO
if(prv->dsa_priv) DSA_free(prv->dsa_priv);
DSA_free(prv->dsa_priv); RSA_free(prv->rsa_priv);
if(prv->rsa_priv)
RSA_free(prv->rsa_priv);
#endif #endif
memset(prv,0,sizeof(PRIVATE_KEY)); memset(prv, 0, sizeof(PRIVATE_KEY));
free(prv); SAFE_FREE(prv);
} }
/** \brief Retrieve a public key from a file /** \brief Retrieve a public key from a file
@@ -825,12 +822,16 @@ static char *lowercase(const char* str) {
/** \brief frees a token array /** \brief frees a token array
* \internal * \internal
*/ */
static void tokens_free(char **tokens){ static void tokens_free(char **tokens) {
free(tokens[0]); if (tokens == NULL) {
/* It's not needed to free other pointers because tokens generated by return;
* space_tokenize fit all in one malloc }
*/
free(tokens); SAFE_FREE(tokens[0]);
/* It's not needed to free other pointers because tokens generated by
* space_tokenize fit all in one malloc
*/
SAFE_FREE(tokens);
} }
/** \brief returns one line of known host file /** \brief returns one line of known host file
* will return a token array containing (host|ip) keytype key * will return a token array containing (host|ip) keytype key