[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] When freeing a cert_list_t, avoid memory leak.
commit 7dbf66713f22b5e04a36d300307a4df7e375e76b
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Thu Sep 19 12:22:49 2013 -0400
When freeing a cert_list_t, avoid memory leak.
We were freeing these on exit, but when we added the dl_status_map
field to them in fddb814f, we forgot to arrange for it to be freed.
I've moved the cert_list_free() code into its own function, and added
an appropriate dsmap_free() call.
Fixes bug 9644; bugfix on 0.2.4.13-alpha.
---
changes/bug9644 | 4 ++++
src/or/routerlist.c | 29 ++++++++++++++++++++++-------
2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/changes/bug9644 b/changes/bug9644
new file mode 100644
index 0000000..51c58a5
--- /dev/null
+++ b/changes/bug9644
@@ -0,0 +1,4 @@
+ o Minor bugfixes:
+ - Fix a small memory leak on exit. (We weren't freeing directory
+ authority certificate download statuses.) Fixes bug 9644; bugfix
+ on 0.2.4.13-alpha.
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index c2220f4..c28de24 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -241,6 +241,27 @@ get_cert_list(const char *id_digest)
return cl;
}
+/** Release all space held by a cert_list_t */
+static void
+cert_list_free(cert_list_t *cl)
+{
+ if (!cl)
+ return;
+
+ SMARTLIST_FOREACH(cl->certs, authority_cert_t *, cert,
+ authority_cert_free(cert));
+ smartlist_free(cl->certs);
+ dsmap_free(cl->dl_status_map, tor_free_);
+ tor_free(cl);
+}
+
+/** Wrapper for cert_list_free so we can pass it to digestmap_free */
+static void
+cert_list_free_(void *cl)
+{
+ cert_list_free(cl);
+}
+
/** Reload the cached v3 key certificates from the cached-certs file in
* the data directory. Return 0 on success, -1 on failure. */
int
@@ -3324,13 +3345,7 @@ routerlist_free_all(void)
smartlist_free(fallback_dir_servers);
trusted_dir_servers = fallback_dir_servers = NULL;
if (trusted_dir_certs) {
- DIGESTMAP_FOREACH(trusted_dir_certs, key, cert_list_t *, cl) {
- SMARTLIST_FOREACH(cl->certs, authority_cert_t *, cert,
- authority_cert_free(cert));
- smartlist_free(cl->certs);
- tor_free(cl);
- } DIGESTMAP_FOREACH_END;
- digestmap_free(trusted_dir_certs, NULL);
+ digestmap_free(trusted_dir_certs, cert_list_free_);
trusted_dir_certs = NULL;
}
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits