]> granicus.if.org Git - curl/commitdiff
Curl_MD5_init: fix OOM memory leak
authorDaniel Stenberg <daniel@haxx.se>
Mon, 23 Apr 2012 21:07:40 +0000 (23:07 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 23 Apr 2012 21:07:40 +0000 (23:07 +0200)
Bug: http://curl.haxx.se/mail/lib-2012-04/0246.html
Reported by: Michael Mueller

lib/md5.c

index e58f2c5151351fc1a9ae8738110ffc044300aff0..8d66d95ec73fb2fba47a876486ab2af7677e9ba2 100644 (file)
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -426,9 +426,9 @@ void Curl_md5it(unsigned char *outbuffer, /* 16 bytes */
   MD5_Final(outbuffer, &ctx);
 }
 
-MD5_context * Curl_MD5_init(const MD5_params *md5params)
+MD5_context *Curl_MD5_init(const MD5_params *md5params)
 {
-  MD5_contextctxt;
+  MD5_context *ctxt;
 
   /* Create MD5 context */
   ctxt = malloc(sizeof *ctxt);
@@ -438,12 +438,14 @@ MD5_context * Curl_MD5_init(const MD5_params *md5params)
 
   ctxt->md5_hashctx = malloc(md5params->md5_ctxtsize);
 
-  if(!ctxt->md5_hashctx)
-    return ctxt->md5_hashctx;
+  if(!ctxt->md5_hashctx) {
+    free(ctxt);
+    return NULL;
+  }
 
   ctxt->md5_hash = md5params;
 
-  (*md5params->md5_init)(ctxt->md5_hashctx);
+  md5params->md5_init(ctxt->md5_hashctx);
 
   return ctxt;
 }