[Issue 11139] New: malloc/emplace resulting in memory corruption

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Sep 29 06:42:24 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=11139

           Summary: malloc/emplace resulting in memory corruption
           Product: D
           Version: D2
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: blocker
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: puneet at coverify.org


--- Comment #0 from Puneet Goel <puneet at coverify.org> 2013-09-29 06:42:22 PDT ---
On my linux box I get:

$ rdmd test.d
4000
$ rdmd -version=EMPLACE test.d
4000
Segmentation fault (core dumped)

The code runs fine if I comment out line 19 or line 23 -- both of which are
producing only a side effect.

class Frop {                                               // 01
  int[] _var;                                              // 02
  int[] var() {                                            // 03
    return _var;                                           // 04
  }                                                        // 05
  this() {                                                 // 06
    this._var.length = 1;                                  // 07
  }                                                        // 08
}                                                          // 09
class Foo {                                                // 10
  long[] nodes;                                            // 11
  Frop[] frops;                                            // 12
  long[] table;                                            // 13
  this() {                                                 // 14
    nodes.length = 120000;                                 // 15
    frops.length = 1;                                      // 16
    frops[0] = new Frop();                                 // 17
    initTable();                                           // 18
    zoo(frops[0].var);                                     // 19
  }                                                        // 20
  void initTable() {                                       // 21
    import std.stdio;                                      // 22
    writeln(4000);                                         // 23
    table.length = 40000;                                  // 24
  }                                                        // 25
  void zoo(int[] varset) {}                                // 26
}                                                          // 27
class Bar {                                                // 28
  Foo _foo;                                                // 29
  this() {                                                 // 30
    version(EMPLACE) {                                     // 31
      import std.conv, core.stdc.stdlib;                   // 32
      enum size_t size = __traits(classInstanceSize, Foo); // 33
      // static assert(size is 32); // 64 on x64           // 34
      void* tmp = core.stdc.stdlib.malloc(size);           // 35
      if (!tmp)                                            // 36
    throw new Exception("Memory allocation failed");   // 37
      void[] mem = tmp[0..size];                           // 38
      _foo = emplace!(Foo)(mem);                           // 39
    }                                                      // 40
    else {                                                 // 41
      _foo = new Foo();                                    // 42
    }                                                      // 43
  }                                                        // 44
}                                                          // 45
void main() {                                              // 46
  auto bar = new Bar;                                      // 47
}                                                          // 48

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list