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

Commit

Permalink
Merge pull request #1508 from MartinNowak/fix15353
Browse files Browse the repository at this point in the history
fix Issue 15353 - ignore freeing during finalization
  • Loading branch information
andralex committed Mar 13, 2016
2 parents bbd797a + 1113bf1 commit f7604ef
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
7 changes: 7 additions & 0 deletions changelog.dd
Expand Up @@ -7,6 +7,7 @@ $(BUGSTITLE Library Changes,

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

$(BUGSTITLE Library Changes,
Expand Down Expand Up @@ -42,6 +43,12 @@ Macros:
COREMODREF = <a href="phobos/core_$1.html">$2</a>
XREF = <a href="phobos/std_$1.html#$2">$2</a>
CXREF = <a href="phobos/core_$1.html#$2">$2</a>
OXREF = <a href="phobos/object.html#$2">$2</a>
NXREF = <a href="phobos/std_$1.html#.$2">$2</a>
NCXREF = <a href="phobos/core_$1.html#.$2">$2</a>
NOXREF = <a href="phobos/object.html#.$2">$2</a>

BUGZILLA = <a href="https://issues.dlang.org/show_bug.cgi?id=$0">Bugzilla $0</a>

BOOKTABLE = <table><caption>$1</caption>$+</table>
PRE = <pre>$0</pre>
12 changes: 6 additions & 6 deletions src/core/memory.d
Expand Up @@ -552,12 +552,12 @@ struct GC


/**
* Deallocates the memory referenced by p. If p is null, no action
* occurs. If p references memory not originally allocated by this
* garbage collector, or if it points to the interior of a memory block,
* no action will be taken. The block will not be finalized regardless
* of whether the FINALIZE attribute is set. If finalization is desired,
* use delete instead.
* Deallocates the memory referenced by p. If p is null, no action occurs.
* If p references memory not originally allocated by this garbage
* collector, if p points to the interior of a memory block, or if this
* method is called from a finalizer, no action will be taken. The block
* will not be finalized regardless of whether the FINALIZE attribute is
* set. If finalization is desired, use delete instead.
*
* Params:
* p = A pointer to the root of a valid memory block or to null.
Expand Down
19 changes: 18 additions & 1 deletion src/gc/gc.d
Expand Up @@ -813,7 +813,7 @@ struct GC
*/
void free(void *p) nothrow
{
if (!p)
if (!p || inFinalizer)
{
return;
}
Expand Down Expand Up @@ -3250,6 +3250,23 @@ unittest // bugzilla 14467
assert(arr.capacity);
}

unittest // bugzilla 15353
{
import core.memory : GC;

static struct Foo
{
~this()
{
GC.free(buf); // ignored in finalizer
}

void* buf;
}
new Foo(GC.malloc(10));
GC.collect();
}

/* ============================ SENTINEL =============================== */


Expand Down

0 comments on commit f7604ef

Please sign in to comment.