[Issue 22505] New: Array relocation causes multiple calls to destructor
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Nov 12 10:04:55 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22505
Issue ID: 22505
Summary: Array relocation causes multiple calls to destructor
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: critical
Priority: P1
Component: druntime
Assignee: nobody at puremagic.com
Reporter: omerfirmak at gmail.com
import std;
import core.memory;
struct B
{
int[] b;
~this ()
{
b[0]++;
writeln(b[0]);
}
}
void main()
{
B[] b_list;
foreach(idx; 0 ..100)
b_list ~= B([0]);
b_list.length = 0;
GC.collect();
}
---------------------------------------------------------
One would assume that B.b[0] would always be 0 before destructor runs. But if
b_list is ever relocated while trying to expand its size, GC will finalize
objects while trying to collect the old memory for b_list and cause all objects
in b_list to be finalized multiple times.
--
More information about the Digitalmars-d-bugs
mailing list