Skip to content

Commit 3cec5ff

Browse files
committed
Close listener in case of error
1 parent 1b57771 commit 3cec5ff

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

libraries/llvm/io.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,6 @@ void c_tcp_close(Int handle, Stack stack) {
317317
uv_close(uv_handle, c_tcp_close_cb);
318318
}
319319

320-
321-
typedef struct {
322-
Stack stack;
323-
struct Pos handler;
324-
} tcp_accept_closure_t;
325-
326320
void c_tcp_listen(String host, Int port, Int backlog, Stack stack) {
327321
// TODO make non-async
328322
char* host_str = c_bytearray_into_nullterminated_string(host);
@@ -343,28 +337,33 @@ void c_tcp_listen(String host, Int port, Int backlog, Stack stack) {
343337
free(host_str);
344338

345339
if (result < 0) {
346-
free(tcp_handle);
340+
uv_close((uv_handle_t*)tcp_handle, (uv_close_cb)free);
347341
resume_Int(stack, result);
348342
return;
349343
}
350344

351345
result = uv_tcp_bind(tcp_handle, (const struct sockaddr*)&addr, 0);
352346
if (result < 0) {
353-
free(tcp_handle);
347+
uv_close((uv_handle_t*)tcp_handle, (uv_close_cb)free);
354348
resume_Int(stack, result);
355349
return;
356350
}
357351

358352
result = uv_listen((uv_stream_t*)tcp_handle, backlog, NULL);
359353
if (result < 0) {
360-
free(tcp_handle);
354+
uv_close((uv_handle_t*)tcp_handle, (uv_close_cb)free);
361355
resume_Int(stack, result);
362356
return;
363357
}
364358

365359
resume_Int(stack, (int64_t)tcp_handle);
366360
}
367361

362+
typedef struct {
363+
Stack stack;
364+
struct Pos handler;
365+
} tcp_accept_closure_t;
366+
368367
void c_tcp_accept_cb(uv_stream_t* server, int status) {
369368
tcp_accept_closure_t* accept_closure = (tcp_accept_closure_t*)server->data;
370369

0 commit comments

Comments
 (0)