Skip to content

Commit 39392b3

Browse files
authored
Merge pull request #3139 from cesanta/freewill
free ifp on mgr_free
2 parents 34cdce7 + 54d4611 commit 39392b3

File tree

6 files changed

+8
-9
lines changed

6 files changed

+8
-9
lines changed

mongoose.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4127,6 +4127,9 @@ void mg_mgr_free(struct mg_mgr *mgr) {
41274127
if (mgr->epoll_fd >= 0) close(mgr->epoll_fd), mgr->epoll_fd = -1;
41284128
#endif
41294129
mg_tls_ctx_free(mgr);
4130+
#if MG_ENABLE_TCPIP
4131+
if (mgr->ifp) mg_tcpip_free(mgr->ifp);
4132+
#endif
41304133
}
41314134

41324135
void mg_mgr_init(struct mg_mgr *mgr) {
@@ -4162,7 +4165,7 @@ void mg_mgr_init(struct mg_mgr *mgr) {
41624165
#endif
41634166

41644167

4165-
#if defined(MG_ENABLE_TCPIP) && MG_ENABLE_TCPIP
4168+
#if MG_ENABLE_TCPIP
41664169
#define MG_EPHEMERAL_PORT_BASE 32768
41674170
#define PDIFF(a, b) ((size_t) (((char *) (b)) - ((char *) (a))))
41684171

src/net.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ void mg_mgr_free(struct mg_mgr *mgr) {
247247
if (mgr->epoll_fd >= 0) close(mgr->epoll_fd), mgr->epoll_fd = -1;
248248
#endif
249249
mg_tls_ctx_free(mgr);
250+
#if MG_ENABLE_TCPIP
251+
if (mgr->ifp) mg_tcpip_free(mgr->ifp);
252+
#endif
250253
}
251254

252255
void mg_mgr_init(struct mg_mgr *mgr) {

src/net_builtin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "net_builtin.h"
22

3-
#if defined(MG_ENABLE_TCPIP) && MG_ENABLE_TCPIP
3+
#if MG_ENABLE_TCPIP
44
#define MG_EPHEMERAL_PORT_BASE 32768
55
#define PDIFF(a, b) ((size_t) (((char *) (b)) - ((char *) (a))))
66

test/fuzz.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
145145
mg_iobuf_add(&c->recv, 0, data, size);
146146
c->pfn(c, MG_EV_READ, NULL); // manually invoke protocol event handler
147147

148-
mg_mgr_free(&mgr);
149148
free(pkt);
150-
mg_tcpip_free(&mif);
151149
}
152150

153151
return 0;

test/mip_tap_test.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ int main(void) {
471471

472472
// Clear
473473
mg_mgr_free(&mgr);
474-
mg_tcpip_free(&mif); // Release after mg_mgr
475474
ASSERT(mgr.conns == NULL); // Deconstruction OK
476475
close(fd);
477476
return 0;

test/mip_test.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ static void test_poll(void) {
8080
mg_http_listen(&mgr, "http://127.0.0.1:12346", ph, &count);
8181
for (i = 0; i < 10; i++) mg_mgr_poll(&mgr, 0);
8282
ASSERT(count == 10);
83-
mg_tcpip_free(&mif);
8483
mg_mgr_free(&mgr);
8584
}
8685

@@ -240,7 +239,6 @@ static void test_retransmit(void) {
240239

241240
s_driver_data.len = 0;
242241
mg_mgr_free(&mgr);
243-
mg_tcpip_free(&mif);
244242
}
245243

246244
static void test_frag_recv_path(void) {
@@ -284,7 +282,6 @@ static void test_frag_recv_path(void) {
284282

285283
s_driver_data.len = 0;
286284
mg_mgr_free(&mgr);
287-
mg_tcpip_free(&mif);
288285
}
289286

290287
static void test_frag_send_path(void) {
@@ -307,7 +304,6 @@ static void test_frag_send_path(void) {
307304
ASSERT(s_seg_sent == 3);
308305
s_driver_data.len = 0;
309306
mg_mgr_free(&mgr);
310-
mg_tcpip_free(&mif);
311307
}
312308

313309
static void test_fragmentation(void) {

0 commit comments

Comments
 (0)