mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-17 19:31:18 +00:00
Fix eventfd leak in uev_event_init()
uev_event_init() leaks its eventfd, and leaves it in the watcher, when the watcher cannot be added to the event loop. Close it and reset the descriptor in the watcher.
This commit is contained in:
1 parent
ae28276f3f
commit
4792b988a1
4 files changed
+46
-2
No files matched your search
+8
-2
@@ -57,8 +57,14 @@ int uev_event_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg)
|
|||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return _uev_watcher_init(ctx, w, UEV_EVENT_TYPE, cb, arg, fd, UEV_READ)
|
if (_uev_watcher_init(ctx, w, UEV_EVENT_TYPE, cb, arg, fd, UEV_READ) ||
|
||||||
|| _uev_watcher_start(w);
|
_uev_watcher_start(w)) {
|
||||||
|
close(fd);
|
||||||
|
w->fd = -1;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ api
|
|||||||
complete
|
complete
|
||||||
cronrun
|
cronrun
|
||||||
cronstart
|
cronstart
|
||||||
|
error
|
||||||
io
|
io
|
||||||
signal
|
signal
|
||||||
stdin
|
stdin
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ TESTS += api
|
|||||||
TESTS += complete
|
TESTS += complete
|
||||||
TESTS += cronrun
|
TESTS += cronrun
|
||||||
TESTS += cronstart
|
TESTS += cronstart
|
||||||
|
TESTS += error
|
||||||
TESTS += io
|
TESTS += io
|
||||||
TESTS += signal
|
TESTS += signal
|
||||||
TESTS += stdin
|
TESTS += stdin
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/* Verifies cleanup on failure to set up a context or watcher */
|
||||||
|
#include "check.h"
|
||||||
|
|
||||||
|
/* A failed uev_event_init() must not leak its eventfd */
|
||||||
|
static void event_init(void)
|
||||||
|
{
|
||||||
|
uev_ctx_t ctx;
|
||||||
|
uev_t w;
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
fail_unless(uev_init(&ctx) == 0);
|
||||||
|
fail_unless(close(ctx.fd) == 0);
|
||||||
|
|
||||||
|
fd = dup(STDIN_FILENO);
|
||||||
|
fail_unless(fd >= 0);
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
fail_unless(uev_event_init(&ctx, &w, NULL, NULL) != 0);
|
||||||
|
fail_unless(w.fd == -1);
|
||||||
|
fail_unless(dup(STDIN_FILENO) == fd);
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
event_init();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
Reference in new issue
Block a user