D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11446 - [GC] GC realloc doesn't ignore non-GC owned pointers
Summary: [GC] GC realloc doesn't ignore non-GC owned pointers
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2013-11-05 10:32 UTC by safety0ff.bugz
Modified: 2019-01-04 02:57 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description safety0ff.bugz 2013-11-05 10:32:28 UTC
According to the documentation [1], GC.realloc should do nothing if passed a non-GC owned pointers.

Currently if passed a non-zero size parameter along with the non-GC pointer it will allocate new memory and copy the contents.


Discussion thread: http://forum.dlang.org/thread/qmiayckycycetnumulbn@forum.dlang.org

[1] http://dlang.org/phobos/core_memory.html#.GC.realloc
Comment 1 Rainer Schuetze 2019-01-03 12:55:59 UTC
https://github.com/dlang/druntime/pull/2436
Comment 2 github-bugzilla 2019-01-04 02:57:00 UTC
Commit pushed to master at https://github.com/dlang/druntime

https://github.com/dlang/druntime/commit/e6087c2fed9e49daaa72296bd951ea56efe82ec7
fix Issue 11393,11446 - [GC] GC realloc and free don't ignore interior/non-GC owned pointers

change specification of GC.realloc to something more robust:

- return null for failure (returning the original pointer is no indication of failure as it might also be returned on success. This can easily lead to overwriting memory)
- allow freeing old memory immediately (previous implementation did this for large objects when shrinking)
- only set attribute bits on existing block if reused (previous implementation didn't set bits if it reused a small block)

refactor realloc to match that spec, add changelog, fix example