Skip to content

Instantly share code, notes, and snippets.

@olsonjeffery
Created February 25, 2012 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olsonjeffery/1904856 to your computer and use it in GitHub Desktop.
Save olsonjeffery/1904856 to your computer and use it in GitHub Desktop.
libuv behavior wrt un_ref()'d uv_async_t handle with pending sends before uv_run()
jeff@mbp ~/src/1904856 $ ./test
hw
uv loop beginning
inside async cb
inside timer cb
closed timer
exiting timer_cb
closing handle
uv loop ended. it leaks, i know.
win:
g++ -I../libuv/include test_case.c ../rust/src/libuv/uv.a -lws2_32 -lm -lIphlpapi -lpsapi -o test
linux:
g++ -I../rust/src/libuv/include test_case.c ../rust/src/libuv/uv.a -lpthread -lm -lnsl -lrt -o test
#include "stdlib.h"
#include "stdio.h"
#include "uv.h"
void close_cb(uv_handle_t* handle) {
printf("closing handle\n");
}
void timer_cb(uv_timer_t* timer, int status) {
uv_handle_t* async = (uv_handle_t*)timer->data;
printf("inside timer cb\n");
uv_close((uv_handle_t*)timer, close_cb);
printf("closed timer\n");
printf("exiting timer_cb\n");
}
void async_cb(uv_async_t* handle, int status) {
printf("inside async cb\n");
uv_timer_t* timer = (uv_timer_t*)malloc(sizeof(uv_timer_t));
uv_timer_init(handle->loop, timer);
timer->data = (uv_handle_t*)handle;
uv_timer_start(timer, timer_cb, 1, 0);
}
int main() {
printf("hw\n");
uv_loop_t* loop = uv_loop_new();
uv_async_t async;
uv_async_init(loop, &async, async_cb);
uv_async_send(&async);
uv_async_send(&async);
uv_async_send(&async); // these will be rolled into a single call
uv_unref(loop);
printf("uv loop beginning\n");
uv_run(loop);
uv_close((uv_handle_t*)&async, close_cb);
printf("uv loop ended. it leaks, i know.\n");
}
$ ./test.exe
hw
uv loop beginning
uv loop ended. it leaks, i know.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment