From 7aa7a2d34e6b85252b7610d1ab688dba0502e058 Mon Sep 17 00:00:00 2001 From: Diederik de Groot Date: Sun, 29 Apr 2018 17:57:38 +0200 Subject: [PATCH] Fix stdio File.open / resetFile / detach / refcount --- std/stdio.d | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/std/stdio.d b/std/stdio.d index 63324903b68..650cb4f0e23 100644 --- a/std/stdio.d +++ b/std/stdio.d @@ -510,17 +510,12 @@ Throws: `ErrnoException` in case of error. import std.conv : text; import std.exception : errnoEnforce; - if (_p is null) + if (_p !is null) { - _p = cast(Impl*) enforce(malloc(Impl.sizeof), "Out of memory"); - } - { - if (atomicOp!"-="(_p.refs, 1) == 0) - closeHandles(); - else - _p = cast(Impl*) enforce(malloc(Impl.sizeof), "Out of memory"); + detach(); } + _p = cast(Impl*) enforce(malloc(Impl.sizeof), "Out of memory"); FILE* handle; version (Posix) {