aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/evp/digest.c
diff options
context:
space:
mode:
authorBen Laurie <ben@openssl.org>2001-08-28 13:45:41 +0000
committerBen Laurie <ben@openssl.org>2001-08-28 13:45:41 +0000
commit1f3b65801b1b0bf11e18c318f7b2c6fcd357e3aa (patch)
tree23401f6ba3ffa417cb0744a6d229d638eddccb76 /crypto/evp/digest.c
parent5e2c4e23f4f42cf31d75ea6735fbdca7011be3be (diff)
downloadopenssl-1f3b65801b1b0bf11e18c318f7b2c6fcd357e3aa.tar.gz
Fix SSL memory leak.
Diffstat (limited to 'crypto/evp/digest.c')
-rw-r--r--crypto/evp/digest.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c
index f1c905ab75..5c5b118486 100644
--- a/crypto/evp/digest.c
+++ b/crypto/evp/digest.c
@@ -75,13 +75,22 @@ EVP_MD_CTX *EVP_MD_CTX_create(void)
return ctx;
}
+#ifdef CRYPTO_MDEBUG
+int EVP_DigestInit_dbg(EVP_MD_CTX *ctx, const EVP_MD *type,const char *file,
+ int line)
+#else
int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
+#endif
{
if(ctx->digest != type)
{
OPENSSL_free(ctx->md_data);
ctx->digest=type;
+#ifdef CRYPTO_MDEBUG
+ ctx->md_data=CRYPTO_malloc(type->ctx_size,file,line);
+#else
ctx->md_data=OPENSSL_malloc(type->ctx_size);
+#endif
}
return type->init(ctx->md_data);
}
@@ -142,7 +151,12 @@ void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
/* This call frees resources associated with the context */
int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
{
- /* assume ctx->md_data was cleaned in EVP_Digest_Final */
+ /* Don't assume ctx->md_data was cleaned in EVP_Digest_Final,
+ * because sometimes only copies of the context are ever finalised.
+ */
+ if(ctx->md_data)
+ memset(ctx->md_data,0,ctx->digest->ctx_size);
+
OPENSSL_free(ctx->md_data);
memset(ctx,'\0',sizeof *ctx);