fixed memleak
authorMartin Willi <martin@strongswan.org>
Tue, 4 Nov 2008 13:01:36 +0000 (13:01 -0000)
committerMartin Willi <martin@strongswan.org>
Tue, 4 Nov 2008 13:01:36 +0000 (13:01 -0000)
src/libstrongswan/plugins/openssl/openssl_rsa_private_key.c

index 205220a..c152b82 100644 (file)
@@ -74,9 +74,10 @@ openssl_rsa_public_key_t *openssl_rsa_public_key_create_from_n_e(BIGNUM *n, BIGN
  * Build an EMPSA PKCS1 signature described in PKCS#1
  */
 static bool build_emsa_pkcs1_signature(private_openssl_rsa_private_key_t *this,
-                                                                          int type, chunk_t data, chunk_t *signature)
+                                                                          int type, chunk_t data, chunk_t *out)
 {
        bool success = FALSE;
+       u_char *sig = NULL;
        u_int len;
        const EVP_MD *hasher = EVP_get_digestbynid(type);
        if (!hasher)
@@ -106,15 +107,17 @@ static bool build_emsa_pkcs1_signature(private_openssl_rsa_private_key_t *this,
                goto error;
        }
        
-       *signature = chunk_alloc(RSA_size(this->rsa));
-       
-       if (!EVP_SignFinal(ctx, signature->ptr, &len, key))
+       sig = malloc(EVP_PKEY_size(key));
+       if (EVP_SignFinal(ctx, sig, &len, key))
        {
-               goto error;
+               out->ptr = sig;
+               out->len = len;
+               success = TRUE;
+       }
+       else
+       {
+               free(sig);
        }
-       signature->len = len;
-       
-       success = TRUE;
        
 error:
        if (key)