www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7022] New: File.byLine doesn't release file handle

reply d-bugmail puremagic.com writes:
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



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: -------
Nov 27 2011
next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Apr 08 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Apr 08 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7022


SomeDude <lovelydear mailmetrash.com> changed:

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



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: -------
Apr 23 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7022




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


fix issue 7022

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




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


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 28 2012
prev sibling parent d-bugmail puremagic.com writes:
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: -------
May 31 2012