Skip to content

Commit

Permalink
File.detach should decrement the ref count - Issue 7022
Browse files Browse the repository at this point in the history
Because detach invalidates a copy of the File struct it should also decrement the ref count.
The File destructor doesn't take care of this because by then p is already null.
  • Loading branch information
MikeWey committed May 21, 2012
1 parent 28bca62 commit bff3254
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions std/stdio.d
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,19 @@ and throws if that fails.
p = null;
}

unittest
{
auto deleteme = testFilename();
scope(exit) std.file.remove(deleteme);
auto f = File(deleteme, "w");
{
auto f2 = f;
f2.detach();
}
assert(f.p.refs == 1);
f.close();
}

/**
If the file was unopened, succeeds vacuously. Otherwise closes the
file (by calling $(WEB
Expand Down

0 comments on commit bff3254

Please sign in to comment.