Comment #0 by safety0ff.bugz — 2013-10-30T18:29:45Z
The documentation / spec [1][2] states that realloc and free should do nothing when they're passed interior pointers.
Currently realloc / free still operate on the underlying memory blocks regardless.
I started working on the fix for realloc but decided that it should really be discussed before spending more time on it.
Discuss :)
----
[1] http://dlang.org/phobos/core_memory.html#.GC.realloc
[2] http://dlang.org/phobos/core_memory.html#.GC.free
Comment #1 by safety0ff.bugz — 2013-10-30T18:41:25Z
I suppose this should have been spit into two bugs, but for now we can keep the discussion focused.
The reason fixing realloc requires discussion is that fixing this may break exiting code in the case where it is passed an interior pointer with a non zero size parameter.
Fixing the case where the pointer is internal and either realloc is called with size zero or free is called does not break existing code unless the GC is disabled, where it will cause memory leaks.
Comment #2 by safety0ff.bugz — 2013-11-03T11:25:28Z
Comment #4 by github-bugzilla — 2019-01-04T02:56:58Z
Commits pushed to master at https://github.com/dlang/druntimehttps://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
https://github.com/dlang/druntime/commit/c1c0a85f5904953b98b2e1b188a650576b83da82
Merge pull request #2436 from rainers/gc_realloc
fix Issue 11393 - [GC] GC realloc and free don't ignore interior pointers
merged-on-behalf-of: Nicholas Wilson <[email protected]>
Comment #5 by dlang-bot — 2020-07-05T10:53:34Z
dlang/druntime pull request #3149 "fix test for issue 11393 introduced by #2436" was merged into master:
- d247d9636ca568b37d7995a253e525b41b6e2d38 by Rainer Schuetze:
fix test for issue 11393
https://github.com/dlang/druntime/pull/3149