63124

Super-weird issue triggering “Segmentation Fault”

I won't go very deep into the issue (the codebase is already thousands of lines and quite complex), so I'll try to miniminise the... "window" to what I've spotted.

<strong>Here's the routine triggering the "Segmentation Fault" :</strong>

extern (C) { void* Statements_new() { return cast(void*)(new Statements()); } void Statements_add(Statements s, Statement st) { //writeln("In here"); if (s is null) writeln("StatemenTS are null"); else writeln("not null : "~ typeid(s).name); if (st is null) writeln("statement is null"); else writeln("not null : " ~ typeid(st).name); s.add(st); //writeln("Out of here"); } }

<strong>A few notes :</strong>

    <li>The declared methods are nothing but "bindings" so that native routines can be called directly from C code (Bison actually).</li> <li>The Statements_add function is called with a Statements object and a subclassed Statement object.</li> </ul>

    <strong>Now, the weirdness of it :</strong>

      <li>The error doesn't happen all the time (actually it doesn't happen like 99% of the time), but when it does, the s.add(st); statement seems the culprit.</li> <li>Never ever is one of the 2 parameters (s,st) null.</li> <li>Now, if I comment the 2 if... writeln... typeid statements, the error is there.</li> <li>If I uncomment them (they don't do anything, huh?), it always works - fixed - bingo!</li> </ul>

      What's going on???

      <hr>

      A few more details :

        <li><strong>Compiler :</strong> DMD64 D Compiler v2.065</li> <li><strong>Debugger :</strong> lldb</li> <li><strong>OS :</strong> OSX 10.9.2</li> </ul>

        Answer1:

        If you are passing the only reference of an object allocated in D code from the D heap to non-D code, then you must either register it as a GC root, or change your code to use malloc instead of allocating from the managed D heap. Otherwise, the GC will think that the object is unused, and collect it to free memory.

Recommend

  • Parse JSON object in C#
  • How to get the name of userfiles in controller to add to database
  • How to stream a file line-by-line in Dart
  • Obtaining the type-name of a template type, without class definition
  • how to extract text from a html element by id and assign to a php variable?
  • In R, find the column that contains a string in for each row
  • Display Local HTML file from documents directory in a UIWebView on iPhone
  • Controls in ItemTemplate can't be called in Code Behind
  • Best way to Update Two common functions to use shared function
  • golang fails to parse json for reflection created object
  • How to get a list of all blobs in a repository in Git
  • Merging Users in Kinvey
  • TextPad “find in files” not matching on simple OR regex
  • Render html in springfox-swagger-ui
  • Angular Databinding doesnt Work
  • Escaping single quotes in JDBC with MySql
  • javascript variables, What does var x = a = {} do?
  • Importing Excel files with a large number of columns header into mysql with c#
  • Iterate twice through a DataReader
  • Cordova Apache wrong module path
  • R sqldf renaming a field in a select statement
  • .NET video play library which allows to change the playback rate?
  • I am receiving HibernateException “No Hibernate Session bound to thread, and configuration does not
  • How can Delete be both a DDL and a DML statement
  • Why does java tzupdater add leap seconds?
  • How to 'create temp table as select' in Slick?
  • pyodbc doesn't report sql server error
  • MySQL Order by column = x, column asc?
  • C: Incompatible pointer type initializing
  • Swift: Switch statement fallthrough behavior
  • Weird JavaScript statement, what does it mean?
  • Compare two NSDates in iPhone
  • Linker errors when using intrinsic function via function pointer
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Angular 2 constructor injection vs direct access
  • Java static initializers and reflection
  • Android Google Maps API OnLocationChanged only called once
  • LevelDB C iterator
  • How can i traverse a binary tree from right to left in java?
  • UserPrincipal.Current returns apppool on IIS