Fixed memory leak and file descriptor leak in known host parsing

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@307 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Aris Adamantiadis
2009-03-29 20:29:55 +00:00
parent 07d748ef5e
commit 1fd7a875be

View File

@@ -789,13 +789,10 @@ static int alldigits(char *s)
* @{ */ * @{ */
/** /**
* @brief Lowercase a string. * \brief Lowercase a string.
* * \param str String to lowercase.
* @param str String to lowercase. * \return The malloced lowered string or NULL on error.
* * \internal
* @return The lowered string or NULL on error.
*
* @internal
*/ */
static char *lowercase(const char* str) { static char *lowercase(const char* str) {
char *p = 0; char *p = 0;
@@ -1061,13 +1058,12 @@ int ssh_is_server_known(SSH_SESSION *session){
match=check_public_key(session,tokens); match=check_public_key(session,tokens);
tokens_free(tokens); tokens_free(tokens);
if(match<0){ if(match<0){
leave_function(); ret = SSH_SERVER_ERROR;
return SSH_SERVER_ERROR; break;
} }
if(match==1){ if(match==1){
fclose(file); ret=SSH_SERVER_KNOWN_OK;
leave_function(); break;
return SSH_SERVER_KNOWN_OK;
} }
if(match==0){ if(match==0){
/* We override the status with the wrong key state */ /* We override the status with the wrong key state */
@@ -1076,6 +1072,8 @@ int ssh_is_server_known(SSH_SESSION *session){
} }
} while (1); } while (1);
SAFE_FREE(host); SAFE_FREE(host);
if(file)
fclose(file);
/* Return the current state at end of file */ /* Return the current state at end of file */
leave_function(); leave_function();
return ret; return ret;