- fixed memleak in sha1
authorMartin Willi <martin@strongswan.org>
Tue, 22 Nov 2005 07:50:19 +0000 (07:50 -0000)
committerMartin Willi <martin@strongswan.org>
Tue, 22 Nov 2005 07:50:19 +0000 (07:50 -0000)
Source/charon/transforms/hashers/hasher.c
Source/charon/transforms/hashers/hasher.h
Source/charon/transforms/hashers/hasher_sha1.c

index 2055824..14ace82 100644 (file)
@@ -34,11 +34,11 @@ hasher_t *hasher_create(hash_algorithm_t hash_algorithm)
 {
        switch (hash_algorithm)
        {
-               case SHA1:
+               case HASH_SHA1:
                {
                        return (hasher_t*)hasher_sha1_create();
                }
-               case MD5:
+               case HASH_MD5:
                default:
                        return NULL;
        }
index ff7fcc3..534d0bf 100644 (file)
@@ -32,8 +32,8 @@
 typedef enum hash_algorithm_e hash_algorithm_t;
 
 enum hash_algorithm_e {
-       SHA1,
-       MD5
+       HASH_SHA1,
+       HASH_MD5
 };
 
 
index 8dfc358..e786271 100644 (file)
@@ -206,22 +206,22 @@ static status_t get_hash(private_hasher_sha1_t *this, chunk_t chunk, u_int8_t *b
 static status_t allocate_hash(private_hasher_sha1_t *this, chunk_t chunk, chunk_t *hash)
 {
        chunk_t allocated_hash;
-       allocated_hash.ptr = allocator_alloc(BLOCK_SIZE_SHA1);
-       allocated_hash.len = BLOCK_SIZE_SHA1;
-       if (allocated_hash.ptr == NULL)
-       {
-               return OUT_OF_RES;
-       }
        
        SHA1Update(this, chunk.ptr, chunk.len);
        if (hash != NULL)
-       {
+       {       
+               allocated_hash.ptr = allocator_alloc(BLOCK_SIZE_SHA1);
+               allocated_hash.len = BLOCK_SIZE_SHA1;
+               if (allocated_hash.ptr == NULL)
+               {
+                       return OUT_OF_RES;
+               }
                SHA1Final(this, allocated_hash.ptr);
                this->public.hasher_interface.reset(&(this->public.hasher_interface));
+               
+               *hash = allocated_hash;
        }
        
-       *hash = allocated_hash;
-       
        return SUCCESS;
 }