ReadyTalk / avian

[INACTIVE] Avian is a lightweight virtual machine and class library designed to provide a useful subset of Java's features, suitable for building self-contained applications.
https://readytalk.github.io/avian/
Other
1.22k stars 173 forks source link

The main temporary file not delete on Lzma mode #458

Open larrylau opened 9 years ago

larrylau commented 9 years ago

The main program will extract On the lzma mode, but The temporary file not delete on exit!

dicej commented 9 years ago

Thanks for reporting this. Are you using Windows by any chance? My guess is that the unlink call at https://github.com/ReadyTalk/avian/blob/836cc4/src/lzma/load.cpp#L153 isn't working because Windows doesn't allow deleting a file while it is loaded as a library.

One possible solution would be to explicitly unload the library and unlink it after mainFunction returns at https://github.com/ReadyTalk/avian/blob/836cc4/src/lzma/load.cpp#L160. I don't have a machine with Windows handy at the moment to try that, but that's what I would recommend.

larrylau commented 9 years ago

I used mingw on win7, consider win32api Createfile with flag FILE_FLAG_DELETE_ON_CLOSE ?

joshuawarner32 commented 9 years ago

@larrylau - Something like that will probably work, although you'll likely have to write the file (per the current method), close that handle, then open the handle again with GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE, and FILE_FLAG_DELETE_ON_CLOSE.

CreateProcess will refuse to load a module with writable handles open to it (or indeed, handles that specify FILE_SHARE_WRITE, IIRC), and I'm assuming LoadLibrary will behave similarly.