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

Commit 1113bf1

Browse files
committed
fix Issue 15353 - ignore freeing during finalization
1 parent bbd797a commit 1113bf1

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

changelog.dd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ $(BUGSTITLE Library Changes,
77

88
$(LI $(RELATIVE_LINK2 aa-clear, A `clear` method has been added to associative
99
arrays to remove all elements.))
10+
$(LI Calls to $(NCXREF memory, GC.free) are now ignored during finalization instead of throwing an InvalidMemoryOperationError, see $(BUGZILLA 15353).)
1011
)
1112

1213
$(BUGSTITLE Library Changes,
@@ -42,6 +43,12 @@ Macros:
4243
COREMODREF = <a href="phobos/core_$1.html">$2</a>
4344
XREF = <a href="phobos/std_$1.html#$2">$2</a>
4445
CXREF = <a href="phobos/core_$1.html#$2">$2</a>
46+
OXREF = <a href="phobos/object.html#$2">$2</a>
47+
NXREF = <a href="phobos/std_$1.html#.$2">$2</a>
48+
NCXREF = <a href="phobos/core_$1.html#.$2">$2</a>
49+
NOXREF = <a href="phobos/object.html#.$2">$2</a>
50+
51+
BUGZILLA = <a href="https://issues.dlang.org/show_bug.cgi?id=$0">Bugzilla $0</a>
4552

4653
BOOKTABLE = <table><caption>$1</caption>$+</table>
4754
PRE = <pre>$0</pre>

src/core/memory.d

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,12 @@ struct GC
552552

553553

554554
/**
555-
* Deallocates the memory referenced by p. If p is null, no action
556-
* occurs. If p references memory not originally allocated by this
557-
* garbage collector, or if it points to the interior of a memory block,
558-
* no action will be taken. The block will not be finalized regardless
559-
* of whether the FINALIZE attribute is set. If finalization is desired,
560-
* use delete instead.
555+
* Deallocates the memory referenced by p. If p is null, no action occurs.
556+
* If p references memory not originally allocated by this garbage
557+
* collector, if p points to the interior of a memory block, or if this
558+
* method is called from a finalizer, no action will be taken. The block
559+
* will not be finalized regardless of whether the FINALIZE attribute is
560+
* set. If finalization is desired, use delete instead.
561561
*
562562
* Params:
563563
* p = A pointer to the root of a valid memory block or to null.

src/gc/gc.d

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ struct GC
813813
*/
814814
void free(void *p) nothrow
815815
{
816-
if (!p)
816+
if (!p || inFinalizer)
817817
{
818818
return;
819819
}
@@ -3250,6 +3250,23 @@ unittest // bugzilla 14467
32503250
assert(arr.capacity);
32513251
}
32523252

3253+
unittest // bugzilla 15353
3254+
{
3255+
import core.memory : GC;
3256+
3257+
static struct Foo
3258+
{
3259+
~this()
3260+
{
3261+
GC.free(buf); // ignored in finalizer
3262+
}
3263+
3264+
void* buf;
3265+
}
3266+
new Foo(GC.malloc(10));
3267+
GC.collect();
3268+
}
3269+
32533270
/* ============================ SENTINEL =============================== */
32543271

32553272

0 commit comments

Comments
 (0)