Permalink
Browse files

ext/io/wait: needs variable which was allocated by xmalloc when invok…

…e rb_fd_init.
  • Loading branch information...
Watson1978 committed Dec 9, 2011
1 parent f6de7df commit ec5096a16864e033094da85265d6cfd52746cb42
Showing with 9 additions and 8 deletions.
  1. +9 −8 ext/io/wait/wait.c
View
@@ -119,7 +119,7 @@ static VALUE
io_wait(int argc, VALUE *argv, VALUE io)
{
rb_io_t *fptr;
- struct wait_readable_arg arg;
+ struct wait_readable_arg *arg;
int fd, i;
ioctl_arg n;
VALUE timeout;
@@ -128,24 +128,25 @@ io_wait(int argc, VALUE *argv, VALUE io)
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
rb_scan_args(argc, argv, "01", &timeout);
+ arg = (struct wait_readable_arg *)xmalloc(sizeof(struct wait_readable_arg));
if (NIL_P(timeout)) {
- arg.timeout = 0;
+ arg->timeout = 0;
}
else {
timerec = rb_time_interval(timeout);
- arg.timeout = &timerec;
+ arg->timeout = &timerec;
}
if (rb_io_read_pending(fptr)) return Qtrue;
if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qfalse;
fd = fptr->fd;
- rb_fd_init(&arg.fds);
- rb_fd_set(fd, &arg.fds);
+ rb_fd_init(&arg->fds);
+ rb_fd_set(fd, &arg->fds);
#ifdef HAVE_RB_FD_INIT
- i = (int)rb_ensure(wait_readable, (VALUE)&arg,
- (VALUE (*)_((VALUE)))rb_fd_term, (VALUE)&arg.fds);
+ i = (int)rb_ensure(wait_readable, (VALUE)arg,
+ (VALUE (*)_((VALUE)))rb_fd_term, (VALUE)&arg->fds);
#else
- i = rb_thread_select(fd + 1, rb_fd_ptr(&arg.fds), NULL, NULL, arg.timeout);
+ i = rb_thread_select(fd + 1, rb_fd_ptr(&arg->fds), NULL, NULL, arg->timeout);
#endif
if (i < 0)
rb_sys_fail(0);

0 comments on commit ec5096a

Please sign in to comment.