mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-17 19:31:18 +00:00
Do not leave stdin as descriptor of a failed context
uev_init() leaves the context descriptor at 0 when epoll_create1() fails. A following uev_exit() then closes stdin. Set it to -1 before creating the epoll descriptor.
This commit is contained in:
1 parent
4792b988a1
commit
05bc6a0830
2 files changed
+22
No files matched your search
@@ -226,6 +226,7 @@ int uev_init1(uev_ctx_t *ctx, int maxevents)
|
|||||||
maxevents = UEV_MAX_EVENTS;
|
maxevents = UEV_MAX_EVENTS;
|
||||||
|
|
||||||
memset(ctx, 0, sizeof(*ctx));
|
memset(ctx, 0, sizeof(*ctx));
|
||||||
|
ctx->fd = -1;
|
||||||
ctx->maxevents = maxevents;
|
ctx->maxevents = maxevents;
|
||||||
|
|
||||||
return _init(ctx, 0);
|
return _init(ctx, 0);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/* Verifies cleanup on failure to set up a context or watcher */
|
/* Verifies cleanup on failure to set up a context or watcher */
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
#include <sys/resource.h>
|
||||||
|
|
||||||
/* A failed uev_event_init() must not leak its eventfd */
|
/* A failed uev_event_init() must not leak its eventfd */
|
||||||
static void event_init(void)
|
static void event_init(void)
|
||||||
@@ -21,9 +22,29 @@ static void event_init(void)
|
|||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* A failed uev_init() must not leave stdin as the context descriptor */
|
||||||
|
static void ctx_init(void)
|
||||||
|
{
|
||||||
|
struct rlimit old, lim;
|
||||||
|
uev_ctx_t ctx;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
fail_unless(getrlimit(RLIMIT_NOFILE, &old) == 0);
|
||||||
|
lim = old;
|
||||||
|
lim.rlim_cur = 0;
|
||||||
|
fail_unless(setrlimit(RLIMIT_NOFILE, &lim) == 0);
|
||||||
|
|
||||||
|
rc = uev_init(&ctx);
|
||||||
|
|
||||||
|
fail_unless(setrlimit(RLIMIT_NOFILE, &old) == 0);
|
||||||
|
fail_unless(rc == -1);
|
||||||
|
fail_unless(ctx.fd == -1);
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
event_init();
|
event_init();
|
||||||
|
ctx_init();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user