Skip to content

Commit cd52113

Browse files
boazsegevioquatix
authored andcommitted
Add if statement, even if redundant
This short PR explores the possibility of adding a slightly redundant `if` statement... The if statement is probably redundant since `rb_gc_mark` tests for special non-allocated "objects" such as `nil`, `false`, embedded numbers etc'). However: (1) since a NULL dereferencing issue was reported; and (2) GC tests this condition only after pushing the stack (so it's faster if we test for it); we might as well add this slightly redundant `if` statement and see if it helps.
1 parent 5baa5ed commit cd52113

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

ext/nio4r/monitor.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ static VALUE NIO_Monitor_allocate(VALUE klass)
6666

6767
static void NIO_Monitor_mark(struct NIO_Monitor *monitor)
6868
{
69-
return rb_gc_mark(monitor->self);
69+
if(monitor && monitor->self)
70+
rb_gc_mark(monitor->self);
7071
}
7172

7273
static void NIO_Monitor_free(struct NIO_Monitor *monitor)

0 commit comments

Comments
 (0)