commit 3197429afa733dad69832c252698a4585bef78ff
parent 5b3281807dc56ef25b832e82859d7f307d5d311e
Author: Michael Savage <mikejsavage@gmail.com>
Date: Sat, 17 Dec 2011 02:23:26 +0000
Remove unnecessary heap allocations
Diffstat:
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/src/luabcrypt.c b/src/luabcrypt.c
@@ -1,4 +1,3 @@
-#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
@@ -14,13 +13,11 @@ static int luabcrypt_digest( lua_State *L )
const char *key = luaL_checkstring( L, 1 );
const char *salt = luaL_checkstring( L, 2 );
- char *hash = malloc( _PASSWORD_LEN );
+ char hash[ _PASSWORD_LEN ];
bcrypt( key, salt, hash );
lua_pushstring( L, hash );
- free( hash );
-
return 1;
}
@@ -30,13 +27,11 @@ static int luabcrypt_gensalt( lua_State *L )
u_int8_t log_rounds = luaL_checkinteger( L, 1 );
// because the OpenBSD implementation says so
- char *salt = malloc( 7 + ( BCRYPT_MAXSALT * 4 + 2 ) / 3 + 1 );
+ char salt[ 7 + ( BCRYPT_MAXSALT * 4 + 2 ) / 3 + 1 ];
bcrypt_gensalt( log_rounds, salt );
lua_pushstring( L, salt );
- free( salt );
-
return 1;
}
@@ -46,15 +41,13 @@ static int luabcrypt_verify( lua_State *L )
const char *key = luaL_checkstring( L, 1 );
const char *digest = luaL_checkstring( L, 2 );
- char *encrypted = malloc( _PASSWORD_LEN );
+ char encrypted[ _PASSWORD_LEN ];
bcrypt( key, digest, encrypted );
int verified = strncmp( encrypted, digest, _PASSWORD_LEN ) == 0;
lua_pushboolean( L, verified );
- free( encrypted );
-
return 1;
}