[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r16965: {tor} Make it easier for dmalloc to see if keys are leaking; remov (tor/trunk/src/or)
Author: nickm
Date: 2008-09-25 13:37:00 -0400 (Thu, 25 Sep 2008)
New Revision: 16965
Modified:
tor/trunk/src/or/test.c
Log:
Make it easier for dmalloc to see if keys are leaking; remove a test-only key leak.
Modified: tor/trunk/src/or/test.c
===================================================================
--- tor/trunk/src/or/test.c 2008-09-25 17:36:09 UTC (rev 16964)
+++ tor/trunk/src/or/test.c 2008-09-25 17:37:00 UTC (rev 16965)
@@ -47,6 +47,7 @@
#ifdef USE_DMALLOC
#include <dmalloc.h>
+#include <openssl/crypto.h>
#endif
int have_failed = 0;
@@ -105,19 +106,31 @@
rmdir(temp_dir);
}
+static crypto_pk_env_t *pregen_keys[5] = {NULL, NULL, NULL, NULL, NULL};
static crypto_pk_env_t *
pk_generate(int idx)
{
- static crypto_pk_env_t *pregen[5] = {NULL, NULL, NULL, NULL, NULL};
- tor_assert(idx < (int)(sizeof(pregen)/sizeof(pregen[0])));
- if (! pregen[idx]) {
- pregen[idx] = crypto_new_pk_env();
- tor_assert(!crypto_pk_generate_key(pregen[idx]));
+ tor_assert(idx < (int)(sizeof(pregen_keys)/sizeof(pregen_keys[0])));
+ if (! pregen_keys[idx]) {
+ pregen_keys[idx] = crypto_new_pk_env();
+ tor_assert(!crypto_pk_generate_key(pregen_keys[idx]));
}
- return crypto_pk_dup_key(pregen[idx]);
+ return crypto_pk_dup_key(pregen_keys[idx]);
}
static void
+free_pregenerated_keys(void)
+{
+ unsigned idx;
+ for (idx = 0; idx < sizeof(pregen_keys)/sizeof(pregen_keys[0]); ++idx) {
+ if (pregen_keys[idx]) {
+ crypto_free_pk_env(pregen_keys[idx]);
+ pregen_keys[idx] = NULL;
+ }
+ }
+}
+
+static void
test_buffers(void)
{
char str[256];
@@ -4405,12 +4418,20 @@
int
main(int c, char**v)
{
- or_options_t *options = options_new();
+ or_options_t *options;
char *errmsg = NULL;
int i;
int verbose = 0, any_selected = 0;
int loglevel = LOG_ERR;
+#ifdef USE_DMALLOC
+ {
+ int r = CRYPTO_set_mem_ex_functions(_tor_malloc, _tor_realloc, _tor_free);
+ tor_assert(r);
+ }
+#endif
+
+ options = options_new();
tor_threads_init();
init_logging();
@@ -4501,6 +4522,7 @@
}
puts("");
+ free_pregenerated_keys();
#ifdef USE_DMALLOC
tor_free_all(0);
dmalloc_log_unfreed();