Skip to content

Commit

Permalink
test allocation for failure and initialize memory
Browse files Browse the repository at this point in the history
This commit addresses the comment made by @tarcieri about the `monitor` object's memory not being initialized.
  • Loading branch information
boazsegev authored and ioquatix committed Sep 15, 2020
1 parent cd52113 commit f6b1810
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ext/nio4r/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ void Init_NIO_Monitor()
static VALUE NIO_Monitor_allocate(VALUE klass)
{
struct NIO_Monitor *monitor = (struct NIO_Monitor *)xmalloc(sizeof(struct NIO_Monitor));


if(!monitor)
return Qnil;

monitor->self = Qnil;
return Data_Wrap_Struct(klass, NIO_Monitor_mark, NIO_Monitor_free, monitor);
}

static void NIO_Monitor_mark(struct NIO_Monitor *monitor)
{
if(monitor && monitor->self)
if(monitor && monitor->self != Qnil)
rb_gc_mark(monitor->self);
}

Expand Down

0 comments on commit f6b1810

Please sign in to comment.