From: Andre Noll Date: Sun, 11 Feb 2007 21:37:49 +0000 (+0100) Subject: fix a memory leak in the RSA key handling X-Git-Tag: v0.2.15~13 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=89b2ebc40332c729be076f6122d1744b205c64bc;p=paraslash.git fix a memory leak in the RSA key handling 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). --- diff --git a/crypt.c b/crypt.c index c1a2d4e5..46a90533 100644 --- 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 2f51ff52..1f7b8a86 100644 --- a/crypt.h +++ b/crypt.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2006 Andre Noll + * Copyright (C) 2005-2007 Andre Noll * * 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 diff --git a/user_list.c b/user_list.c index 3d57a945..1143f2d5 100644 --- a/user_list.c +++ b/user_list.c @@ -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