Closed boazsegev closed 3 years ago
See comments in #244 as to why I propose this extra if
statement
Note that monitor->self
is never explicitly set to NULL, so this change alone doesn't make sense.
It's initialized in NIO_Monitor_initialize
:
https://github.com/socketry/nio4r/blob/77f859a/ext/nio4r/monitor.c#L107
Prior to that it's uninitialized. If you'd like to add this NULL check, I would suggest initializing monitor->self
to NULL
in NIO_Monitor_allocate
.
Thanks @tarcieri - I added code to validate that the allocation was successful and to initialize the memory.
I am in doubt if this was the issue, but these validations make for cleaner and safer code. For example, allocation failure should have been tested for and memory initialization is a good practice that protects against some hard to catch bugs.
I get a failure:
In file included from nio4r_ext.c:6:
./../libev/ev.c:54:12: fatal error: 'config.h' file not found
# include "config.h"
This isn't me... I didn't touch that.
This isn't me... I didn't touch that.
Not sure what's up with that. Any ideas @ioquatix?
FYI:
I tested the PR on my machine and I think it solved the issue that was commented upon in PR #244
Cool!
Thanks everyone for figuring this out. I'll do another point release.
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 asnil
,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.