RFR: 8340307: Add explanation around MemorySegment:reinterpret regarding arenas [v4]

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Oct 31 17:33:30 UTC 2024


On Thu, 31 Oct 2024 14:32:46 GMT, Per Minborg <pminborg at openjdk.org> wrote:

>> This PR proposes to add a small text segment on the `MemorySegment::reinterpret` overloads that takes an Arena stating the responsibility of actually freeing reinterpreted segments lies with the *original* arena.
>
> Per Minborg has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Improve docs

src/java.base/share/classes/java/lang/foreign/MemorySegment.java line 772:

> 770:      *     <li>The reinterpreted segment can be accessed <em>after</em> its region
> 771:      *         of memory has been deallocated via the original arena (use after free).</li>
> 772:      *     <li>The reinterpreted segment's region of memory will <em>not</em> be

On a second look, perhaps this second assertion doesn't add much. Perhaps we can rewrite more succinctly as:

This might lead to *use after free*, as the returned segment can be accessed <em>after</em> its region of memory has been deallocated via this segment's arena.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/21761#discussion_r1824888310


More information about the core-libs-dev mailing list