[Issue 11139] malloc/emplace resulting in memory corruption
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Sep 29 19:33:07 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11139
--- Comment #1 from Puneet Goel <puneet at coverify.org> 2013-09-29 19:33:05 PDT ---
Another reduced testcase. This one does not have dependency on writeln.
class Frop { // 01
void zoo(int ) { } // 02
} // 03
class Foo { // 04
int[] table; // 05
int[] table2; // 06
Frop frop; // 07
this() { // 08
frop = new Frop(); // 09
table2.length = 1; // 10
table.length = 320000; // 11
frop.zoo(0); // 12
} // 13
} // 14
class Bar { // 15
Foo foo; // 16
this() { // 17
version(EMPLACE) { // 18
import std.conv, core.stdc.stdlib; // 19
enum size_t size = __traits(classInstanceSize, Foo); // 20
static assert (size % size_t.sizeof is 0); // 21
void* tmp = core.stdc.stdlib.malloc(size); // 22
if (!tmp) // 23
throw new Exception("Memory allocation failed"); // 24
void[] mem = tmp[0..size]; // 25
foo = emplace!(Foo)(mem); // 26
} // 27
else { // 28
foo = new Foo(); // 29
} // 30
} // 31
} // 32
void main() { // 33
auto bar = new Bar; // 34
} // 35
--
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