-
-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avoid possible junk data in monitor
through memory initialization
#248
Conversation
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.
See comments in #244 as to why I propose this extra |
Note that It's initialized in 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 |
This commit addresses the comment made by @tarcieri about the `monitor` object's memory not being initialized.
While allocating the object, we might as well initialize the whole memory block to zero in order to protect against hidden issues.
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:
This isn't me... I didn't touch that. |
Not sure what's up with that. Any ideas @ioquatix? |
Should resolve the review offered by @tarcieri .
Co-authored-by: Tony Arcieri <bascule@gmail.com>
if
statement, even if redundantmonitor
through memory initialization
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.