TCP server leads to memory leaking #3711
ChivenZhang
started this conversation in
General
Replies: 1 comment
-
You never free memory in this snippet, so that is not libuv's fault (libuv does not often allocate or free memory for you) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The code below in main function has been found memory leak with windows 10 task monitor. When i post 10000 requests to server with JMeter, it happens. Expect fixing !!! Thanx
auto loop = (uv_loop_t*)malloc(sizeof(uv_loop_t));
uv_loop_init(loop);
uv_tcp_t server;
uv_tcp_init(loop, &server);
struct sockaddr_in addr;
uv_ip4_addr("0.0.0.0", 8888, &addr);
int result = uv_tcp_bind(&server, (const struct sockaddr*)&addr, 0);
if (result) {
printf("Could not bind server to port %d. Reason: %s\n", 8888, uv_strerror(result));
return;
}
result = uv_listen((uv_stream_t*)&server, 128,
[](uv_stream_t* server, int status) {
if (status < 0) {
fprintf(stderr, "New connection error %s\n", uv_strerror(status));
return;
}
uv_tcp_t* client = (uv_tcp_t*)malloc(sizeof(uv_tcp_t));
uv_tcp_init(server->loop, client);
if (uv_accept(server, (uv_stream_t*)client) == 0) {
uv_close((uv_handle_t*)client, nullptr);
}
else {
uv_close((uv_handle_t*)client, nullptr);
}
});
if (result) {
printf("Could not listen. Reason: %s\n", uv_strerror(result));
return;
}
uv_run(loop, UV_RUN_DEFAULT);
uv_loop_close(loop);
Beta Was this translation helpful? Give feedback.
All reactions