Skip to content

Commit

Permalink
Fix bogus FileStream destruction warning.
Browse files Browse the repository at this point in the history
The warning in its previous form was too general. It is only an actual problem if the last reference to a FileStream is leaked to the GC, as long as it is ensured that the file gets closed before the GC attempts to finalize the last copy, everything is safe.

See #412
  • Loading branch information
s-ludwig committed Sep 13, 2024
1 parent a9d38be commit f574d66
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions source/vibe/core/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,11 @@ scope:
nothrow {
static if (is(typeof(&eventDriver.files.isUnique))) {
if (this.isOpen) {
if (m_ctx.driver is (() @trusted => cast(shared)eventDriver)() && eventDriver.files.isUnique(m_fd)) {
try close();
catch (Exception e) logException(e, "Closing unclosed FileStream during destruction failed");
if (m_ctx.driver is (() @trusted => cast(shared)eventDriver)()) {
if (eventDriver.files.isUnique(m_fd)) {
try close();
catch (Exception e) logException(e, "Closing unclosed FileStream during destruction failed");
}
} else logWarn("Destroying FileStream that is still open in a foreign thread (leaked to GC?). This may lead to crashes.");
}
}
Expand Down

0 comments on commit f574d66

Please sign in to comment.