]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
crypt: Introduce crypt_shutdown().
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 29 Dec 2017 15:22:37 +0000 (16:22 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 25 Feb 2018 23:10:28 +0000 (00:10 +0100)
This plugs a few harmless memory leaks in the openssl crypto
backend. The leaks occur on exit and are only reported by valgrind
if it is run with --leak-check=full --show-leak-kinds=all.

The gcrypt backend has similar problems, but there is no way to
provide a similar patch for libgrypt. The newly added comment in
gcrypt.c explains why.

audiod.c
client.c
crypt.h
gcrypt.c
openssl.c
server.c

index 4e6cf8e148aeb3156a584f20e0752b8b2e30c41d..083c2a7a1cef606a80afe4ec67b6c9f453fc5bf6 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -1542,7 +1542,7 @@ int main(int argc, char *argv[])
        audiod_cleanup();
        sched_shutdown(&sched);
        signal_shutdown(signal_task);
-
+       crypt_shutdown();
 out:
        lls_free_parse_result(lpr, CMD_PTR);
        if (errctx)
index 1d8a399ae948cae059e71c51ec141f7de3f4edfa..c45826ab645741755e4ab836edc7f26bcd1bf442 100644 (file)
--- a/client.c
+++ b/client.c
@@ -664,6 +664,7 @@ int main(int argc, char *argv[])
                }
        }
        sched_shutdown(&sched);
+       crypt_shutdown();
 out:
        if (ret < 0)
                PARA_ERROR_LOG("%s\n", para_strerror(-ret));
diff --git a/crypt.h b/crypt.h
index 9c09face115ab7f4b465cdb1504a754a61ffa673..85629591880ad03f2d2d010f194667be1db4c121 100644 (file)
--- a/crypt.h
+++ b/crypt.h
@@ -89,6 +89,8 @@ void get_random_bytes_or_die(unsigned char *buf, int num);
  */
 void crypt_init(void);
 
+/** Allocate all resources of the crypto backend. */
+void crypt_shutdown(void);
 
 /** Opaque structure for stream ciphers. */
 struct stream_cipher;
index 5c05ba20badce165aa1f1369136ab90e5d9b41d9..705d0d87a86e0608e9856d9fa197cedb01b439dc 100644 (file)
--- a/gcrypt.c
+++ b/gcrypt.c
@@ -70,6 +70,15 @@ void crypt_init(void)
        srandom(seed);
 }
 
+void crypt_shutdown(void)
+{
+       /*
+        * WK does not see a way to apply a patch for the sake of Valgrind, so
+        * as of 2018 libgrypt has no deinitialization routine to free the
+        * resources on exit.
+        */
+}
+
 /** S-expression for the public part of an RSA key. */
 #define RSA_PUBKEY_SEXP "(public-key (rsa (n %m) (e %m)))"
 /** S-expression for a private RSA key. */
index 70a13aaab0b40339e3f042566a555c266375ad00..7d5bb25d53cf73009803fe0e62ca15d0167a05cb 100644 (file)
--- a/openssl.c
+++ b/openssl.c
@@ -55,6 +55,11 @@ void crypt_init(void)
        srandom(seed);
 }
 
+void crypt_shutdown(void)
+{
+       CRYPTO_cleanup_all_ex_data();
+}
+
 static int get_private_key(const char *path, RSA **rsa)
 {
        EVP_PKEY *pkey;
index 07a38f44a80436ae79dc89136478e4498d4ca9d8..aba056881adb35da513480fffadd8a54b85f5513 100644 (file)
--- a/server.c
+++ b/server.c
@@ -456,6 +456,7 @@ static int init_afs(int argc, char **argv)
                int i;
 
                afs_pid = getpid();
+               crypt_shutdown();
                for (i = argc - 1; i >= 0; i--)
                        memset(argv[i], 0, strlen(argv[i]));
                i = argc - lls_num_inputs(cmdline_lpr) - 1;
@@ -610,6 +611,7 @@ int main(int argc, char *argv[])
        mutex_lock(mmd_mutex);
        ret = schedule(&sched);
        sched_shutdown(&sched);
+       crypt_shutdown();
        lls_free_parse_result(server_lpr, CMD_PTR);
        if (server_lpr != cmdline_lpr)
                lls_free_parse_result(cmdline_lpr, CMD_PTR);