I am initializing a loop in libuv, but if I need to return after I initialized the loop but before I have called uv_run
, how do I correctly clean up all memory and file descriptors? Here is my example code, loop
being uv_loop_t*
and server
being uv_tcp_t*
:
if (uv_loop_init(loop) < 0) {
return -1;
}
if (uv_tcp_init(loop, server) < 0) {
// What code here?
return -1;
}
if (some_other_function() < 0) {
// What code here?
return -1;
}
uv_run(loop, UV_RUN_DEFAULT);
According to this question, I should stop, walk and run the loop, closing all the handles; but that assumes I'm already running the loop, which I'm not. I could just call uv_loop_close(loop)
, but that doesn't free the handles.