Skip to content
New issue

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

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

Already on GitHub? # to your account

Using OTL with runtime package and dynamic loaded libraries causes AV. #132

Closed
sglienke opened this issue Mar 19, 2019 · 2 comments
Closed

Comments

@sglienke
Copy link

Using OTL from a runtime package and dynamically loaded other libraries causes AVs.

The reason for this is that somewhere inside the OTL mechanics the passed callbacks are captured and later cleared which might happen when the original library that was doing a call to the OTL was unloaded already. Trying to free any captured objects or the anonymous method instance itself will then trigger an AV - see attached project.

To solve this issue there should be a Shutdown procedure to finalize/destroy all OTL pieces that are otherwise only ever destroyed when their finalization blocks are being run which happens when the runtime package gets unloaded where the code resides in. With a runtime package this usually happens when the application ends. At that point even other modules that are using the OTL are already unloaded due to the library loading order (even if not dynamically loading them as shown in the example)

OTLShutdownIssue.zip

@sglienke
Copy link
Author

Found the issue - here is the fix:

procedure TOmniTaskExecutor.Cleanup;
begin
  oteWorkerIntf := nil;
+  {$IFDEF OTL_Anonymous}
+  oteFunc := nil;
+  {$ENDIF OTL_Anonymous}
  FreeAndNil(oteTimers);
end; { TOmniTaskExecutor.Cleanup }

This will release the reference on the anonymous method after executing it and the entire reference chain that might be attached to it. I am however not sure if this is the only place that might be missing such a line as there are other places within OTL that store anonymous method references which might be kept for too long.

@gabr42
Copy link
Owner

gabr42 commented Mar 22, 2019

Confirmed. Thank you for the fix!

@gabr42 gabr42 closed this as completed in 577c93b Mar 22, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants