Fix stdio File.open / resetFile / detach / refcount#6484
Fix stdio File.open / resetFile / detach / refcount#6484dlang-bot merged 1 commit intodlang:stablefrom
Conversation
|
Thanks for your pull request and interest in making D better, @dkgroot! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "stable + phobos#6484" |
|
@klickverbot Thanks for adding @JackStouffer ! |
|
Side Question / Unrelated: Or was the use of these 'mismatched' quotes intensional ? This quoting style is seen in multiple location in std/stdio.d. |
That style of quoting is frequently used in some places, like GNU documentation, though I think it is now considered outdated... in any case, it's probably intentional. |
|
@CyberShadow |
|
@CyberShadow Thanks for the links, learned something :-) Still don't like it, but will have to live with them i guess. Funny how you can be around for 45 odd years and never having noticed this quotation style being used before, guess i wasn't paying attention :-) |
|
For the record, @CyberShadow is right - when I wrote those quotes I just followed a style popular at the time. |
|
@dkgroot I changed the base branch to stable as to get this into a release sooner. Can you please |
57b136d to
f6a6e49
Compare
std/stdio.d
Outdated
| detach(); | ||
| } | ||
|
|
||
| if (_p is null) |
There was a problem hiding this comment.
No need for this now, as it will always be true. detach marks p as null.
There was a problem hiding this comment.
Thanks for the review / update... Removed second _p is null check.
JackStouffer
left a comment
There was a problem hiding this comment.
Please squish your changes.
7f737ae to
6b005ee
Compare
6b005ee to
7aa7a2d
Compare
Since #6382 was merged running phobos unittests will cause this (on DFly):
Looking at the sources the resetFile function looks suspect:
Orig source:
Notice, there is no else between these two blocks, so we always decrement _p.refs after the initial allocation of _p, which does not make sense. Just adding 'else' inbetween these blocks is not going to help.
If this decrement does not make the refs go to zero, we malloc _p again (memory leak ?). In short, if we are not (re-)opening a previously opened file, this results in malloc/free/malloc. If there was a previously open file (ie: _p ! is null) and only a single reference (refs==1) then we close the previous file, but do not malloc _p again before using it (null dereference down the line ?). If there were more references, we decrement the refcount by one and then malloc _p a second time. None of this really makes a lot of sense (to me, but maybe i am just missing something).
Reusing the detach function instead of trying to re-implement seems like the right choice in this situation.
BTW: Would it have been possible to use std/typecons RefCounted instead of reimplementing it locally/partially ?