]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
fix a memory leak in the RSA key handling
authorAndre Noll <maan@systemlinux.org>
Sun, 11 Feb 2007 21:37:49 +0000 (22:37 +0100)
committerAndre Noll <maan@systemlinux.org>
Sun, 11 Feb 2007 21:37:49 +0000 (22:37 +0100)
RSA keys must be freed by using openssl's RSA_free() rather than the
usual free(). This leak turns out to be more serious as the amount
of leaked memory increased by about 300 bytes every time para_server
reread the user list (i.e. the hup command was executed or para_server
received SIGHUP).

crypt.c
crypt.h
user_list.c

diff --git a/crypt.c b/crypt.c
index c1a2d4e5c8ccd67007ab96bf751ef9d35eaf465b..46a90533489696df9c3fb2eff665535b3bf2e0bf 100644 (file)
--- a/crypt.c
+++ b/crypt.c
@@ -65,6 +65,19 @@ int get_rsa_key(char *key_file, RSA **rsa, int private)
        return RSA_size(*rsa);
 }
 
+/**
+ * free an RSA structure
+ *
+ * \param rsa pointer to the RSA struct to free
+ *
+ * This must be called for any key obtained by get_rsa_key().
+ */
+void rsa_free(RSA *rsa)
+{
+       if (rsa)
+               RSA_free(rsa);
+}
+
 /**
  * decrypt a buffer using an RSA key
  *
diff --git a/crypt.h b/crypt.h
index 2f51ff52977d0f413ab7cfb5eb9384524289adb7..1f7b8a867b1aea2a52c53f03275372b4fca849d9 100644 (file)
--- a/crypt.h
+++ b/crypt.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2006 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2005-2007 Andre Noll <maan@systemlinux.org>
  *
  *     This program is free software; you can redistribute it and/or modify
  *     it under the terms of the GNU General Public License as published by
@@ -29,6 +29,8 @@ int para_decrypt_buffer(char *key_file, unsigned char *outbuf, unsigned char *in
        int rsa_inlen);
 int get_rsa_key(char *key_file, RSA **rsa, int private);
 
+void rsa_free(RSA *rsa);
+
 /** \cond used to distinguish between loading of private/public key */
 #define LOAD_PUBLIC_KEY 0
 #define LOAD_PRIVATE_KEY 1
index 3d57a9454e87e745e29811a99dc19d2dbf534eb5..1143f2d58aa1605d77324fea14bf682e409d1ab4 100644 (file)
@@ -108,7 +108,7 @@ void init_user_list(char *user_list_file)
                list_for_each_entry_safe(u, tmp, &user_list, node) {
                        list_del(&u->node);
                        free(u->name);
-                       free(u->rsa);
+                       rsa_free(u->rsa);
                        free(u);
                }
        } else