Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File not closed properly when loaded using an IOStream #145

Open
azurefx opened this issue Dec 1, 2018 · 1 comment
Open

File not closed properly when loaded using an IOStream #145

azurefx opened this issue Dec 1, 2018 · 1 comment

Comments

@azurefx
Copy link

azurefx commented Dec 1, 2018

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:\>
@azurefx
Copy link
Author

azurefx commented Dec 4, 2018

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.

azurefx added a commit to azurefx/ImageMagick.jl that referenced this issue Dec 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant