Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit f496294

Browse files
authored
Merge pull request #2108 from wilzbach/__delete-segfault
__delete shouldn't segfault for null merged-on-behalf-of: Steven Schveighoffer <schveiguy@users.noreply.github.com>
2 parents 6dd5d20 + 0723ae5 commit f496294

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/core/memory.d

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,14 +1010,16 @@ void __delete(T)(ref T x) @system
10101010
static assert(0, "It is not possible to delete: `" ~ T.stringof ~ "`");
10111011
}
10121012

1013-
static if (is(T == interface) || is(T == class))
1013+
static if (is(T == interface) ||
1014+
is(T == class) ||
1015+
is(T == U2*, U2))
10141016
{
10151017
GC.free(cast(void*) x);
10161018
x = null;
10171019
}
1018-
else static if (is(T == U2*, U2) || is(T : E2[], E2))
1020+
else static if (is(T : E2[], E2))
10191021
{
1020-
GC.free(&x);
1022+
GC.free(x.ptr);
10211023
x = null;
10221024
}
10231025
}
@@ -1151,4 +1153,17 @@ unittest
11511153
{
11521154
Object x = null;
11531155
__delete(x);
1156+
1157+
struct S { ~this() { } }
1158+
class C { }
1159+
interface I { }
1160+
1161+
int[] a; __delete(a);
1162+
S[] as; __delete(as);
1163+
C c; __delete(c);
1164+
I i; __delete(i);
1165+
C* pc = &c; __delete(*pc);
1166+
I* pi = &i; __delete(*pi);
1167+
int* pint; __delete(pint);
1168+
S* ps; __delete(ps);
11541169
}

0 commit comments

Comments
 (0)