Skip to content

Commit ffa11f5

Browse files
marvinbornerphischu
authored andcommitted
Fix stdlib/network (#1063)
This fixes a memory leak and increases the backlog of uv_listen to SOMAXCONN, such that connections are put in a queue when the previous acceptor is not yet finished (this is the case with a timeout, which triggers the connects at the same time) Another memory leak remains which I couldn't find. ``` ==130847== 128 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==130847== at 0x48577A8: malloc (vg_replace_malloc.c:446) ==130847== by 0x4003F90: ??? (in server_client) ==130847== by 0x4004499: ??? (in server_client) ==130847== by 0x4004557: run (in server_client) ==130847== by 0x4004A1C: spawn_4055 (in server_client) ==130847== by 0x40044F6: resume_Int (in server_client) ==130847== by 0x4002BA0: c_tcp_listen (io.c:367) ==130847== by 0x4004B65: listen_4331 (in server_client) ==130847== by 0x400CA5D: effektMain (in server_client) ==130847== by 0x4003D60: main (main.c:37) ```
1 parent 9afdcd2 commit ffa11f5

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

examples/benchmarks/input_output/server_client.effekt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def main() = {
2020

2121
println("started")
2222

23-
val results = array::build(2) { i =>
23+
val results = array::build(10) { i =>
2424
promise(box {
2525
with on[IOError].result
2626
wait(1000)
@@ -46,4 +46,4 @@ def main() = {
4646
shutdown(listener)
4747

4848
println(total)
49-
}
49+
}

libraries/llvm/io.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ void c_tcp_connect(String host, Int port, Stack stack) {
216216

217217
struct sockaddr_in addr;
218218
result = uv_ip4_addr(host_str, port, &addr);
219+
free(host_str);
219220

220221
if (result < 0) {
221222
free(tcp_handle);
222223
free(connect_req);
223-
free(host_str);
224224
resume_Int(stack, result);
225225
return;
226226
}
@@ -230,7 +230,6 @@ void c_tcp_connect(String host, Int port, Stack stack) {
230230
if (result < 0) {
231231
free(tcp_handle);
232232
free(connect_req);
233-
free(host_str);
234233
resume_Int(stack, result);
235234
return;
236235
}
@@ -243,6 +242,7 @@ typedef struct {
243242
} tcp_read_closure_t;
244243

245244
void c_tcp_read_cb(uv_stream_t* stream, ssize_t bytes_read, const uv_buf_t* buf) {
245+
(void)(buf);
246246
tcp_read_closure_t* read_closure = (tcp_read_closure_t*)stream->data;
247247
Stack stack = read_closure->stack;
248248

@@ -253,6 +253,7 @@ void c_tcp_read_cb(uv_stream_t* stream, ssize_t bytes_read, const uv_buf_t* buf)
253253
}
254254

255255
void c_tcp_read_alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
256+
(void)(suggested_size);
256257
tcp_read_closure_t* read_closure = (tcp_read_closure_t*)handle->data;
257258
buf->base = read_closure->data;
258259
buf->len = read_closure->size;
@@ -414,7 +415,7 @@ void c_tcp_accept(Int listener, struct Pos handler, Stack stack) {
414415
accept_closure->handler = handler;
415416
server->data = accept_closure;
416417

417-
int result = uv_listen(server, 0, c_tcp_accept_cb);
418+
int result = uv_listen(server, SOMAXCONN, c_tcp_accept_cb);
418419
if (result < 0) {
419420
free(accept_closure);
420421
erasePositive(handler);

libraries/llvm/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,5 @@ int main(int argc, char *argv[]) {
3737
effektMain();
3838
uv_loop_t *loop = uv_default_loop();
3939
uv_run(loop, UV_RUN_DEFAULT);
40-
uv_loop_close(loop);
41-
return 0;
40+
return uv_loop_close(loop);
4241
}

0 commit comments

Comments
 (0)