ImageMagick.jl
ImageMagick.jl copied to clipboard
File not closed properly when loaded using an IOStream
ImageMagick v0.7.1 FileIO v1.0.4 Windows 10 x64 17763
When a file is loaded with an open IOStream (MagickReadImageFile), the file gets locked until the julia process exits. However the native MagickReadImage function (called by load(filename)) can release the file correctly.
To reproduce this problem, open a PWSH (elevated):
PS C:\> Copy-Item .\img1.jpg -Destination img2.jpg
PS C:\> julia --banner=no
julia> using Images
julia> using FileIO
julia> size(load("img1.jpg"))
(1080, 1920)
julia> rm("img1.jpg")
julia> io=open("img2.jpg")
IOStream(<file img2.jpg>)
julia> size(load(io))
(1080, 1920)
julia> close(io)
julia> rm("img2.jpg")
ERROR: IOError: unlink: resource busy or locked (EBUSY)
Stacktrace:
[1] uv_error at .\libuv.jl:85 [inlined]
[2] unlink(::String) at .\file.jl:722
[3] #rm#9(::Bool, ::Bool, ::Function, ::String) at .\file.jl:253
[4] rm(::String) at .\file.jl:245
[5] top-level scope at none:0
julia> exit()
PS C:\> Remove-Item .\img2.jpg
PS C:\>
The HANDLE to img2.jpg is duplicated somewhere (after calling load(io)), and close(io) can only close the original HANDLE. If I force close the duplicated handle in procexp, the file is released then.
------UPDATE This bug is caused by Libc.FILE(stream) in read/writeimage function, which dup() the file HANDLE.