]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
gcrypt-util: fix memleak
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 5 Feb 2018 08:54:57 +0000 (09:54 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 5 Feb 2018 08:55:03 +0000 (09:55 +0100)
src/basic/gcrypt-util.c
src/basic/gcrypt-util.h

index 1bfb776725ccfd35f5e1dfcd4e1c20501ad916d9..34d0d399b7c40e3356090bcd247b6322c196a52e 100644 (file)
@@ -42,7 +42,7 @@ void initialize_libgcrypt(bool secmem) {
 }
 
 int string_hashsum(const char *s, size_t len, int md_algorithm, char **out) {
-        gcry_md_hd_t md = NULL;
+        _cleanup_(gcry_md_closep) gcry_md_hd_t md = NULL;
         size_t hash_size;
         void *hash;
         char *enc;
index 69faf08e56fd5ddab79b64a68097c24cedf9e90a..714cae673bb791dd4837025c644ab07cecc99972 100644 (file)
@@ -20,6 +20,8 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#pragma once
+
 #include <errno.h>
 #include <stdbool.h>
 #include <stddef.h>
 #if HAVE_GCRYPT
 #include <gcrypt.h>
 
+#include "macro.h"
+
 void initialize_libgcrypt(bool secmem);
 int string_hashsum(const char *s, size_t len, int md_algorithm, char **out);
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(gcry_md_hd_t, gcry_md_close);
 #endif
 
 static inline int string_hashsum_sha224(const char *s, size_t len, char **out) {