diff --git a/src/common/compat_libevent.c b/src/common/compat_libevent.c index 10489bf296..b5e9cc9332 100644 --- a/src/common/compat_libevent.c +++ b/src/common/compat_libevent.c @@ -237,6 +237,16 @@ tor_init_libevent_rng(void) return rv; } +/** + * Un-initialize libevent in preparation for an exit + */ +void +tor_libevent_free_all(void) +{ + event_base_free(the_event_base); + the_event_base = NULL; +} + #if defined(LIBEVENT_VERSION_NUMBER) && \ LIBEVENT_VERSION_NUMBER >= V(2,1,1) && \ !defined(TOR_UNIT_TESTS) diff --git a/src/common/compat_libevent.h b/src/common/compat_libevent.h index 0cdb73fbb9..1853e50917 100644 --- a/src/common/compat_libevent.h +++ b/src/common/compat_libevent.h @@ -52,6 +52,7 @@ const char *tor_libevent_get_method(void); void tor_check_libevent_header_compatibility(void); const char *tor_libevent_get_version_str(void); const char *tor_libevent_get_header_version_str(void); +void tor_libevent_free_all(void); int tor_init_libevent_rng(void); diff --git a/src/or/main.c b/src/or/main.c index aae98dd8ab..bebe9fff44 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -3388,6 +3388,7 @@ tor_free_all(int postfork) if (!postfork) { release_lockfile(); } + tor_libevent_free_all(); /* Stuff in util.c and address.c*/ if (!postfork) { escaped(NULL);