Bug 19522 – [GC] GC.query/addrOf/sizeOf fail for freed memory
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-12-30T10:14:56Z
Last change time
2018-12-31T13:14:32Z
Assigned to
No Owner
Creator
Rainer Schuetze
Comments
Comment #0 by r.sagitario — 2018-12-30T10:14:56Z
According to the documentation https://dlang.org/phobos/core_memory.html#.GC.query query functions should return null/0 if the pointer "references memory not originally allocated by this garbage collector". But this program fails a couple of asserts:
import core.memory;
void main()
{
void* large = GC.malloc(10000);
GC.free(large);
assert(GC.query(large).base == null);
assert(GC.query(large).size == 0);
assert(GC.addrOf(large) == null);
assert(GC.sizeOf(large) == 0); // fails
void* small = GC.malloc(100);
GC.free(small);
assert(GC.query(small).base == null); // fails
assert(GC.query(small).size == 0); // fails
assert(GC.addrOf(small) == null); // fails
assert(GC.sizeOf(small) == 0); // fails
}
GC.getAttr/setAttr/clrAttr have a similar issue, they also don't check for interior pointers.
Similar stuff happens if the pointer happens to hit an address within a GC memory pool, with arbitrary return values.
Comment #1 by github-bugzilla — 2018-12-31T13:14:31Z