[glib/glib-2-30] g_hmac_get_string: don't allocate and leak an unused buffer



commit 510f221b9e33b4dcbf41c1ff9f0b98bb3b5579a6
Author: Simon McVittie <simon mcvittie collabora co uk>
Date:   Mon Dec 12 18:34:47 2011 +0000

    g_hmac_get_string: don't allocate and leak an unused buffer
    
    Also document why we're not actually using the buffer for anything.
    
    Signed-off-by: Simon McVittie <simon mcvittie collabora co uk>
    Bug: https://bugzilla.gnome.org/show_bug.cgi?id=666113
    Reviewed-by: Emmanuele Bassi <ebassi linux intel com>

 glib/ghmac.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
---
diff --git a/glib/ghmac.c b/glib/ghmac.c
index 3405117..fe6e4cc 100644
--- a/glib/ghmac.c
+++ b/glib/ghmac.c
@@ -279,9 +279,13 @@ g_hmac_get_string (GHmac *hmac)
   g_return_val_if_fail (hmac != NULL, NULL);
 
   digest_len = g_checksum_type_get_length (hmac->digest_type);
-  buffer = g_malloc (digest_len);
+  buffer = g_alloca (digest_len);
 
+  /* This is only called for its side-effect of updating hmac->digesto... */
   g_hmac_get_digest (hmac, buffer, &digest_len);
+  /* ... because we get the string from the checksum rather than
+   * stringifying buffer ourselves
+   */
   return g_checksum_get_string (hmac->digesto);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]