Bug 11594 – synchronized causing segfault instead of Error.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-24T11:42:32Z
Last change time
2017-08-16T13:22:33Z
Assigned to
No Owner
Creator
Shammah Chancellor

Comments

Comment #0 by shammah.chancellor — 2013-11-24T11:42:32Z
I'm not sure why this segfaults, since core.sync.mutex has an in contract to check for null? I am compiling in debug mode. import std.stdio; private Object mut;// = new Object(); void lockedFunction() { synchronized(mut) //I asume this makes does auto mutex = new Mutex(mut) and then mutex.lock()? { writefln("Whoops"); } //mutex.unlock();? /* Also results in segfault: auto mutex = new Mutex(mut); mutex.lock(); writefln("Whoops"); mutex.unlock(); */ } void main() { lockedFunction(); }
Comment #1 by dlang-bugzilla — 2017-07-05T19:01:47Z
I can't reproduce this with either today's compiler or 2.064. In your code, you have: private Object mut;// = new Object(); Does that mean that you instantiate it somewhere? Because if it's not instantiated (i.e. your code is ran verbatim), it does result is a segmentation fault as you described, but only because the object used for locking is null. If you can still reproduce this today and can provide a complete test case, please reopen.
Comment #2 by shammah.chancellor — 2017-07-05T21:58:28Z
(In reply to Vladimir Panteleev from comment #1) > I can't reproduce this with either today's compiler or 2.064. > > In your code, you have: > > private Object mut;// = new Object(); > > Does that mean that you instantiate it somewhere? Because if it's not > instantiated (i.e. your code is ran verbatim), it does result is a > segmentation fault as you described, but only because the object used for > locking is null. > > If you can still reproduce this today and can provide a complete test case, > please reopen. The issue is that when compiled in debug mode, the "in" contract on core.sync.mutex is not checked. This should generate an exception detailing where the error was made when you try to synchronize on an uninitialized object, rather than a segfault (when in debug mode)
Comment #3 by github-bugzilla — 2017-07-06T10:51:41Z
Commit pushed to master at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/a2ead6dd04efdfeb283b72daf167e85fe8db9c49 Fix issue 11594: Check if the monitor is null in _d_monitorenter In case of ``` synchronized (null) { // ... } ``` runtime will try to access __monitor field on a null, without checking if it's a null and it will segfault, leaving programmer clueless. https://issues.dlang.org/show_bug.cgi?id=11594
Comment #4 by dlang-bugzilla — 2017-07-07T06:25:11Z
Oops, looks like I misunderstood the issue. Thanks for the clarification; and for the fix, Nemanja.
Comment #5 by github-bugzilla — 2017-08-07T12:25:55Z
Commit pushed to newCTFE at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/a2ead6dd04efdfeb283b72daf167e85fe8db9c49 Fix issue 11594: Check if the monitor is null in _d_monitorenter
Comment #6 by github-bugzilla — 2017-08-16T13:22:33Z
Commit pushed to stable at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/a2ead6dd04efdfeb283b72daf167e85fe8db9c49 Fix issue 11594: Check if the monitor is null in _d_monitorenter