www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15840] New: std.typecons.RefCounted segfaults when checking


          Issue ID: 15840
           Summary: std.typecons.RefCounted segfaults when checking
                    isInitialized, then segfaults GDB
           Product: D
           Version: D2
          Hardware: x86_64
               URL: https://github.com/cyisfor/story-generator
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: dlang verge.info.tm

I was using d2sqlite3, which uses RefCounted to manage cleanup of all the
prepared statements, and it... started segfaulting. It's very consistent now,
though I honestly can't rule out memory corruption from somewhere else that has
nothing to do with this code. But, it also might be some edge case nobody's run
into before. 

Basically, I call stmt.inject(), which tries to assert that p.handle (a C
pointer) is not NULL (and it's not NULL, as far as I can tell). Since p is
RefCounted, p.handle invokes RefCounted.refCountedPayload() presumably to get
the object that has .handle, and inside refCountedPayload() there is a sanity
check for if the reference counting thingy has been initialized.

So "return (_store !is null)" pretty much. That causes a segmentation fault.

When in gdb, after that error I do
$ p _store
then gdb itself segfaults, and silently dies.

I instrumented all the destructors to make sure, and nothing is being used
after getting destroyed. Since RefCounted was ostensibly being used to allow
blit copying, I also put  disable this(this) in the structures in d2sqlite3,
and dealt with that logistics nightmare, and I still get a segmentation fault.
The segfault is not happening during program shut down, but inside a normal
statement, beneath the main function. The only thing I can think is that
RefCounted is somehow the problem.

I'm using the latest DMD, and phobos, and druntime (as of earlier today), as
well as the latest GDB. DMD is compiled without DEBUG=1, and both phobos and
druntime are compiled with BUILD=debug. And otherwise it's the default "dub"

Mar 27 2016