Thread overview
[Issue 7022] New: File.byLine doesn't release file handle
Nov 27, 2011
Andrej Mitrovic
Apr 08, 2012
Mike Wey
Apr 08, 2012
Ellery Newcomer
Apr 23, 2012
SomeDude
May 31, 2012
Kenji Hara
November 27, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=7022

           Summary: File.byLine doesn't release file handle
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2011-11-27 15:21:59 PST ---
import std.stdio;
import std.file;
import std.process;

void test()
{
    auto file = File("test.txt", "r");
    foreach (line; file.byLine)  // remove and bug goes away
    {
    }
}

void main()
{
    system("echo blabla > test.txt");  // create file externally
    test();
    std.file.remove("test.txt");
}

std.file.FileException@std\file.d(549): test.txt: The process cannot access the file because it is being used by another process.

Btw this has nothing to do with that system call, you can remove it if you have a test.txt file.

As a workaround I can use scope(exit){ file.close(); }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 08, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7022


Mike Wey <mike-wey@planet.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mike-wey@planet.nl


--- Comment #1 from Mike Wey <mike-wey@planet.nl> 2012-04-08 08:10:35 PDT ---
byChunk is also affected by this bug, it's caused by File.detatch which is called by the byLine and byChunk ranges when they reach the end of the file.

But detach currently doesn't decrement the ref count while invalidating a copy of the File.

https://github.com/D-Programming-Language/phobos/pull/530

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 08, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7022


Ellery Newcomer <ellery-newcomer@utulsa.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ellery-newcomer@utulsa.edu


--- Comment #2 from Ellery Newcomer <ellery-newcomer@utulsa.edu> 2012-04-08 15:47:39 PDT ---
ha. I totally beat you to this bug. but unittests are good.

Note your patch will also fix issue 7831

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 23, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7022


SomeDude <lovelydear@mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear@mailmetrash.com


--- Comment #3 from SomeDude <lovelydear@mailmetrash.com> 2012-04-23 04:04:53 PDT ---
No need to say, you can as a workaround call file.close() after the loop

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7022



--- Comment #4 from github-bugzilla@puremagic.com 2012-05-20 15:34:22 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/f1566faeafec6715f227cb7d3bbe3af3737de4b3
fix issue 7022
fix issue 7831

detach sets p=null, which makes it kind of hard for the destructor to actually close the file or decrement the reference count.

https://github.com/D-Programming-Language/phobos/commit/f41c9c48a7edca92fbc0f4f2bf81a7d99c79fcc2 Merge pull request #527 from mylodon/fix-issues-7831-7022

fix issue 7022

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 28, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7022



--- Comment #5 from github-bugzilla@puremagic.com 2012-05-28 14:19:34 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/bff3254afc020df1fd55565930c394993334d509 File.detach should decrement the ref count - Issue 7022

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.

https://github.com/D-Programming-Language/phobos/commit/fa52571d8c7d128393fae5b61f0018d53726425f Merge pull request #530 from MikeWey/patch-1

File.detach should decrement the ref count - Issue 7022

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 31, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7022


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------