[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Introduce circpad free_all() function.
commit 69a277f635d9f5d6e40d1f1e85110621b5c49169
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date: Wed Apr 17 14:52:51 2019 +0300
Introduce circpad free_all() function.
---
src/app/main/shutdown.c | 1 +
src/core/or/circuitpadding.c | 37 +++++++++++++++++++++++++++++++++++++
src/core/or/circuitpadding.h | 6 ++++++
3 files changed, 44 insertions(+)
diff --git a/src/app/main/shutdown.c b/src/app/main/shutdown.c
index 1871717ad..e4dcaa132 100644
--- a/src/app/main/shutdown.c
+++ b/src/app/main/shutdown.c
@@ -139,6 +139,7 @@ tor_free_all(int postfork)
dos_free_all();
circuitmux_ewma_free_all();
accounting_free_all();
+ circpad_free_all();
if (!postfork) {
config_free_all();
diff --git a/src/core/or/circuitpadding.c b/src/core/or/circuitpadding.c
index 1a46296d1..c0caacf58 100644
--- a/src/core/or/circuitpadding.c
+++ b/src/core/or/circuitpadding.c
@@ -37,6 +37,13 @@
* When a padding machine reaches the END state, it gets wiped from the circuit
* so that other padding machines can take over if needed (see
* circpad_machine_spec_transitioned_to_end()).
+ *
+ ****************************
+ * General notes:
+ *
+ * All used machines should be heap allocated and placed into
+ * origin_padding_machines/relay_padding_machines so that they get correctly
+ * cleaned up by the circpad_free_all() function.
**/
#define CIRCUITPADDING_PRIVATE
@@ -2885,6 +2892,36 @@ circpad_handle_padding_negotiated(circuit_t *circ, cell_t *cell,
return 0;
}
+/** Free memory allocated by this machine spec. */
+STATIC void
+machine_spec_free_(circpad_machine_spec_t *m)
+{
+ if (!m) return;
+
+ tor_free(m->states);
+ tor_free(m);
+}
+
+/** Free all memory allocated by the circuitpadding subsystem. */
+void
+circpad_free_all(void)
+{
+ if (origin_padding_machines) {
+ SMARTLIST_FOREACH_BEGIN(origin_padding_machines,
+ circpad_machine_spec_t *, m) {
+ machine_spec_free(m);
+ } SMARTLIST_FOREACH_END(m);
+ smartlist_free(origin_padding_machines);
+ }
+ if (relay_padding_machines) {
+ SMARTLIST_FOREACH_BEGIN(relay_padding_machines,
+ circpad_machine_spec_t *, m) {
+ machine_spec_free(m);
+ } SMARTLIST_FOREACH_END(m);
+ smartlist_free(relay_padding_machines);
+ }
+}
+
/* Serialization */
// TODO: Should we use keyword=value here? Are there helpers for that?
#if 0
diff --git a/src/core/or/circuitpadding.h b/src/core/or/circuitpadding.h
index 059896ddf..c7c5f6c69 100644
--- a/src/core/or/circuitpadding.h
+++ b/src/core/or/circuitpadding.h
@@ -738,7 +738,13 @@ circpad_machine_spec_transition, (circpad_machine_runtime_t *mi,
circpad_decision_t circpad_send_padding_cell_for_callback(
circpad_machine_runtime_t *mi);
+void circpad_free_all(void);
+
#ifdef CIRCUITPADDING_PRIVATE
+STATIC void machine_spec_free_(circpad_machine_spec_t *m);
+#define machine_spec_free(chan) \
+ FREE_AND_NULL(circpad_machine_spec_t,machine_spec_free_, (m))
+
STATIC circpad_delay_t
circpad_machine_sample_delay(circpad_machine_runtime_t *mi);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits