[systemd-devel] hash context not closed.

Stef Bon stefbon at gmail.com
Sat Feb 3 20:14:40 UTC 2018


The testing of the new code requires me too much (meson is required..
and I don't want to replace my existing systemd) and I do not expect
to add more patches is near future.

I've got a patch:

diff --git a/src/basic/gcrypt-util.c b/src/basic/gcrypt-util.c
index 1bfb77672..c7c07e3b7 100644
--- a/src/basic/gcrypt-util.c
+++ b/src/basic/gcrypt-util.c
@@ -46,6 +46,7 @@ int string_hashsum(const char *s, size_t len, int
md_algorithm, char **out) {
         size_t hash_size;
         void *hash;
         char *enc;
+        int res=-EIO;

         initialize_libgcrypt(false);

@@ -59,14 +60,24 @@ int string_hashsum(const char *s, size_t len, int
md_algorithm, char **out) {
         gcry_md_write(md, s, len);

         hash = gcry_md_read(md, 0);
+
         if (!hash)
-                return -EIO;
+                goto closemd;

+        res = -ENOMEM;
         enc = hexmem(hash, hash_size);
-        if (!enc)
-                return -ENOMEM;

-        *out = enc;
-        return 0;
+        if (enc) {
+
+            *out = enc;
+            res = 0;
+
+        }
+
+        closemd:
+
+        gcry_md_close(md);
+
+        return res;
 }
 #endif

Stef


More information about the systemd-devel mailing list