From 54d4611eb61c2561f6fcddcfa522356bd38c25a6 Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Thu, 15 May 2025 17:26:30 -0300 Subject: [PATCH] call mg_tcpip_free from mg_mgr_free() --- mongoose.c | 5 ++++- src/net.c | 3 +++ src/net_builtin.c | 2 +- test/fuzz.c | 2 -- test/mip_tap_test.c | 1 - test/mip_test.c | 4 ---- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/mongoose.c b/mongoose.c index bc26146b..b4798476 100644 --- a/mongoose.c +++ b/mongoose.c @@ -4127,6 +4127,9 @@ void mg_mgr_free(struct mg_mgr *mgr) { if (mgr->epoll_fd >= 0) close(mgr->epoll_fd), mgr->epoll_fd = -1; #endif mg_tls_ctx_free(mgr); +#if MG_ENABLE_TCPIP + if (mgr->ifp) mg_tcpip_free(mgr->ifp); +#endif } void mg_mgr_init(struct mg_mgr *mgr) { @@ -4162,7 +4165,7 @@ void mg_mgr_init(struct mg_mgr *mgr) { #endif -#if defined(MG_ENABLE_TCPIP) && MG_ENABLE_TCPIP +#if MG_ENABLE_TCPIP #define MG_EPHEMERAL_PORT_BASE 32768 #define PDIFF(a, b) ((size_t) (((char *) (b)) - ((char *) (a)))) diff --git a/src/net.c b/src/net.c index deab43c9..37659834 100644 --- a/src/net.c +++ b/src/net.c @@ -247,6 +247,9 @@ void mg_mgr_free(struct mg_mgr *mgr) { if (mgr->epoll_fd >= 0) close(mgr->epoll_fd), mgr->epoll_fd = -1; #endif mg_tls_ctx_free(mgr); +#if MG_ENABLE_TCPIP + if (mgr->ifp) mg_tcpip_free(mgr->ifp); +#endif } void mg_mgr_init(struct mg_mgr *mgr) { diff --git a/src/net_builtin.c b/src/net_builtin.c index 2a096c1e..c027e57e 100644 --- a/src/net_builtin.c +++ b/src/net_builtin.c @@ -1,6 +1,6 @@ #include "net_builtin.h" -#if defined(MG_ENABLE_TCPIP) && MG_ENABLE_TCPIP +#if MG_ENABLE_TCPIP #define MG_EPHEMERAL_PORT_BASE 32768 #define PDIFF(a, b) ((size_t) (((char *) (b)) - ((char *) (a)))) diff --git a/test/fuzz.c b/test/fuzz.c index 1285ae63..0f818434 100644 --- a/test/fuzz.c +++ b/test/fuzz.c @@ -145,9 +145,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { mg_iobuf_add(&c->recv, 0, data, size); c->pfn(c, MG_EV_READ, NULL); // manually invoke protocol event handler - mg_mgr_free(&mgr); free(pkt); - mg_tcpip_free(&mif); } return 0; diff --git a/test/mip_tap_test.c b/test/mip_tap_test.c index 75cffd48..612f611d 100644 --- a/test/mip_tap_test.c +++ b/test/mip_tap_test.c @@ -471,7 +471,6 @@ int main(void) { // Clear mg_mgr_free(&mgr); - mg_tcpip_free(&mif); // Release after mg_mgr ASSERT(mgr.conns == NULL); // Deconstruction OK close(fd); return 0; diff --git a/test/mip_test.c b/test/mip_test.c index 8934345c..4f418b08 100644 --- a/test/mip_test.c +++ b/test/mip_test.c @@ -80,7 +80,6 @@ static void test_poll(void) { mg_http_listen(&mgr, "http://127.0.0.1:12346", ph, &count); for (i = 0; i < 10; i++) mg_mgr_poll(&mgr, 0); ASSERT(count == 10); - mg_tcpip_free(&mif); mg_mgr_free(&mgr); } @@ -240,7 +239,6 @@ static void test_retransmit(void) { s_driver_data.len = 0; mg_mgr_free(&mgr); - mg_tcpip_free(&mif); } static void test_frag_recv_path(void) { @@ -284,7 +282,6 @@ static void test_frag_recv_path(void) { s_driver_data.len = 0; mg_mgr_free(&mgr); - mg_tcpip_free(&mif); } static void test_frag_send_path(void) { @@ -307,7 +304,6 @@ static void test_frag_send_path(void) { ASSERT(s_seg_sent == 3); s_driver_data.len = 0; mg_mgr_free(&mgr); - mg_tcpip_free(&mif); } static void test_fragmentation(void) {