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

Commit cc1f526

Browse files
ibuclawdlang-bot
authored andcommitted
fix Issue 22779 - druntime: Calling __delete with null pointer-to-struct segfaults
1 parent 7e0c6b5 commit cc1f526

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/core/memory.d

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,10 @@ void __delete(T)(ref T x) @system
12291229
else static if (is(T == U*, U))
12301230
{
12311231
static if (is(U == struct))
1232-
_destructRecurse(*x);
1232+
{
1233+
if (x)
1234+
_destructRecurse(*x);
1235+
}
12331236
}
12341237
else static if (is(T : E[], E))
12351238
{
@@ -1334,6 +1337,10 @@ unittest
13341337
assert(a is null);
13351338
assert(dtorCalled);
13361339
assert(GC.addrOf(cast(void*) a) == null);
1340+
1341+
// https://issues.dlang.org/show_bug.cgi?id=22779
1342+
A *aptr;
1343+
__delete(aptr);
13371344
}
13381345

13391346
/// Deleting arrays

0 commit comments

Comments
 (0)