Skip to content

Commit 726567a

Browse files
committed
Final memory leak problem fix.
1 parent 954af93 commit 726567a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/main.c3

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import std::thread;
66
import std::net;
77
import std::net::tcp;
88

9-
// TODO FIX MEMORY LEAK
10-
119
import std::os::win32;
1210

1311
struct WsaData @if(env::WIN32) {
@@ -40,8 +38,12 @@ import std::collections::map;
4038
fn int process(void* arg) {
4139
//mem::@report_heap_allocs_in_scope() {
4240
TcpSocket* socket = arg;
43-
defer socket.close()!!;
44-
defer allocator::destroy_temp_allocators();
41+
42+
defer {
43+
socket.close()!!;
44+
allocator::free(&allocator::LIBC_ALLOCATOR, arg);
45+
allocator::destroy_temp_allocators();
46+
}
4547

4648
HttpRequest req;
4749
if (catch anyfault err = req.read(socket)) {
@@ -111,7 +113,7 @@ $endif
111113

112114
//mem::@report_heap_allocs_in_scope() {
113115
thread::Thread thread;
114-
thread.create(&process, @tclone(socket))!!;
116+
thread.create(&process, allocator::clone(&allocator::LIBC_ALLOCATOR, socket))!!;
115117
thread.detach()!!;
116118
//};
117119
}

0 commit comments

Comments
 (0)