Skip to content

Commit a1e1a3a

Browse files
authored
attach finalizer in mmap to the correct object (#54210)
Fixes #54128
1 parent 6f569c7 commit a1e1a3a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

stdlib/Mmap/src/Mmap.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ function mmap(io::IO,
256256
end # os-test
257257
# convert mmapped region to Julia Array at `ptr + (offset - offset_page)` since file was mapped at offset_page
258258
A = unsafe_wrap(Array, convert(Ptr{T}, UInt(ptr) + UInt(offset - offset_page)), dims)
259-
finalizer(A) do x
259+
finalizer(A.ref.mem) do x
260260
@static if Sys.isunix()
261261
systemerror("munmap", ccall(:munmap, Cint, (Ptr{Cvoid}, Int), ptr, mmaplen) != 0)
262262
else

stdlib/Mmap/test/runtests.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ if !(Sys.ARCH === :powerpc64le || Sys.ARCH === :ppc64le)
100100
s = open(file, "r")
101101
m = mmap(s)
102102
@test_throws ReadOnlyMemoryError m[5] = UInt8('x') # tries to setindex! on read-only array
103-
finalize(m); m=nothing; GC.gc()
103+
finalize(m); m=nothing;
104104
end
105-
105+
GC.gc()
106106
write(file, "Hello World\n")
107107

108108
s = open(file, "r")
@@ -336,8 +336,9 @@ open(file, "r+") do s
336336
finalize(A); A = nothing; GC.gc()
337337
A = mmap(s, Vector{UInt8}, (10,), 1)
338338
Mmap.sync!(A)
339-
finalize(A); A = nothing; GC.gc()
339+
finalize(A); A = nothing;
340340
end
341+
GC.gc()
341342
rm(file)
342343

343344
@testset "Docstrings" begin

0 commit comments

Comments
 (0)