0
votes

I made a simple tool (LogAndMailApplication) that sends logs to my gmail account, for this I used the Indy component TIdSSLIOHandlerSocketOpenSSL. To work it needs ssleay32.dll and libeay32.dll.

So at application start I extract from exe resources the 2 dll and I copy them to the application folder.

All the indy compoennts are in a datamodule I destroy before closing the application.

After destroying the datamodule I try to delete the dlls but I cannot.

I just used DeleteFile, but that worked great for all the other files I delete on application exit (incluging an ini file).

I tried to make a simple exe that just deletes the 2 dll and it works. So the problem is that the 2 dll are somehow locked until the LogAndMailApplication is not closed, how to solve the problem?

3
if the DLLs are hidden in the executable, how can users or administrators replace the DLLS by a newer version, if they need a critical security patch? - mjn
They cannot, but it is not something that makes sense here. I am just sending an e-mail to myself. I install this on 3 customers only, so for now it is managable. - LaBracca
Why do you need to delete the DLLs at all? Why not just keep them there in the application directory so they're ready to use next time? (And for that matter, why don't you just make the installer put them there?) - Rob Kennedy
If your application extracts the dll's to the application folder, it will require to run with elevated privileges on vista or newer windows with UAC enabled (the default). As Rob suggest, the installer should put them there. - jachguate
Ok. this is just a quick and dirty tool, i don't need an installer. - LaBracca

3 Answers

5
votes

Indy dynamically loads the OpenSSL DLLs at runtime, and then by default does not unload them until app shutdown. If you want to unload the DLLs sooner, you need to call IdSSLOpenSSL.UnLoadOpenSSLLibrary() directly. This will unload the DLLs and clean up all references and allocated objects related to them.

3
votes

You can do the following: at the very end of your code use

FreeLibrary(GetModuleHandle('ssleay32.dll')); FreeLibrary(GetModuleHandle('libeay32.dll')); DeleteFile(PathToDLL1); DeleteFile(PathToDLL2);

This should work.

Alternatively you can get rid of OpenSSL and use SSL components from our SecureBlackbox.

1
votes

Alternatively you can delete the DLL's in the finalization section of the data module unit...