Skip to content

Commit

Permalink
attach finalizer in mmap to the correct object (#54210)
Browse files Browse the repository at this point in the history
Fixes #54128
  • Loading branch information
KristofferC authored and DilumAluthge committed Jun 3, 2024
1 parent 97e38cb commit 9b97d12
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion stdlib/Mmap/src/Mmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ function mmap(io::IO,
end # os-test
# convert mmapped region to Julia Array at `ptr + (offset - offset_page)` since file was mapped at offset_page
A = unsafe_wrap(Array, convert(Ptr{T}, UInt(ptr) + UInt(offset - offset_page)), dims)
finalizer(A) do x
finalizer(A.ref.mem) do x
@static if Sys.isunix()
systemerror("munmap", ccall(:munmap, Cint, (Ptr{Cvoid}, Int), ptr, mmaplen) != 0)
else
Expand Down
7 changes: 4 additions & 3 deletions stdlib/Mmap/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ if !(Sys.ARCH === :powerpc64le || Sys.ARCH === :ppc64le)
s = open(file, "r")
m = mmap(s)
@test_throws ReadOnlyMemoryError m[5] = UInt8('x') # tries to setindex! on read-only array
finalize(m); m=nothing; GC.gc()
finalize(m); m=nothing;
end

GC.gc()
write(file, "Hello World\n")

s = open(file, "r")
Expand Down Expand Up @@ -336,8 +336,9 @@ open(file, "r+") do s
finalize(A); A = nothing; GC.gc()
A = mmap(s, Vector{UInt8}, (10,), 1)
Mmap.sync!(A)
finalize(A); A = nothing; GC.gc()
finalize(A); A = nothing;
end
GC.gc()
rm(file)

@testset "Docstrings" begin
Expand Down

0 comments on commit 9b97d12

Please sign in to comment.