diff options
author | Alex Xu (Hello71) <alex_y_xu@yahoo.ca> | 2022-04-19 22:50:31 -0400 |
---|---|---|
committer | Alex Xu (Hello71) <alex_y_xu@yahoo.ca> | 2022-04-20 00:14:25 -0400 |
commit | 15e95c3bda1e3781a7f7175de4e65a749e9d6a2c (patch) | |
tree | 12b339464465d1dea2c2ee6c4542e3de17ba5991 /src/test/test_connection.c | |
parent | 616c06c0b2748db163cbb6882043d24fdbaaf335 (diff) | |
download | tor-15e95c3bda1e3781a7f7175de4e65a749e9d6a2c.tar.gz tor-15e95c3bda1e3781a7f7175de4e65a749e9d6a2c.zip |
Use tor_event_free instead of event_del+tor_free
Using tor_free is wrong; event_free must be called for objects obtained from
event_new. Additionally, this slightly simplifies the code.
Also, add a static_assert to prevent further instances.
Diffstat (limited to 'src/test/test_connection.c')
-rw-r--r-- | src/test/test_connection.c | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/src/test/test_connection.c b/src/test/test_connection.c index fbf9d6a5ab..ed94fe8aaa 100644 --- a/src/test/test_connection.c +++ b/src/test/test_connection.c @@ -22,6 +22,7 @@ #include "feature/dircommon/directory.h" #include "core/or/connection_or.h" #include "lib/net/resolve.h" +#include "lib/evloop/compat_libevent.h" #include "test/test_connection.h" #include "test/test_helpers.h" @@ -113,14 +114,8 @@ test_conn_get_basic_teardown(const struct testcase_t *tc, void *arg) /* We didn't call tor_libevent_initialize(), so event_base was NULL, * so we can't rely on connection_unregister_events() use of event_del(). */ - if (conn->linked_conn->read_event) { - tor_free(conn->linked_conn->read_event); - conn->linked_conn->read_event = NULL; - } - if (conn->linked_conn->write_event) { - tor_free(conn->linked_conn->write_event); - conn->linked_conn->write_event = NULL; - } + tor_event_free(conn->linked_conn->read_event); + tor_event_free(conn->linked_conn->write_event); if (!conn->linked_conn->marked_for_close) { connection_close_immediate(conn->linked_conn); @@ -142,14 +137,8 @@ test_conn_get_basic_teardown(const struct testcase_t *tc, void *arg) /* We didn't set the events up properly, so we can't use event_del() in * close_closeable_connections() > connection_free() * > connection_unregister_events() */ - if (conn->read_event) { - tor_free(conn->read_event); - conn->read_event = NULL; - } - if (conn->write_event) { - tor_free(conn->write_event); - conn->write_event = NULL; - } + tor_event_free(conn->read_event); + tor_event_free(conn->write_event); if (!conn->marked_for_close) { connection_close_immediate(conn); |