D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15809 - Putting std.stdio.File.ByLine in a class causes Invalid memory operation upon exit
Summary: Putting std.stdio.File.ByLine in a class causes Invalid memory operation upon...
Status: RESOLVED DUPLICATE of issue 15822
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-18 19:04 UTC by hsteoh
Modified: 2016-03-23 08:29 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description hsteoh 2016-03-18 19:04:24 UTC
Reduced code:
------
import std.stdio;
class Wrapper
{
    typeof(stdin.byLine()) src;
}
void main()
{
    auto x = new Wrapper();
    x.src = stdin.byLine(); 
}
------

Compiled with git HEAD, upon program exit, the following error is triggered:
------
core.exception.InvalidMemoryOperationError@src/core/exception.d(693): Invalid memory operation
------

Commenting out the second line in main() makes the problem go away.

Works with older releases of dmd toolchain.
Comment 1 ag0aep6g 2016-03-22 16:00:26 UTC
See also issue 15821. It's very similar which suggests that there's a dmd/druntime bug beneath.
Comment 2 ag0aep6g 2016-03-22 17:35:11 UTC
It boils down to this:

----
alias T = void*;
struct RefCounted
{
    T* _store;

    this(int dummy)
    {
        import core.memory : GC;
        import core.stdc.stdlib : malloc;
        _store = cast(T*)malloc(T.sizeof);
        GC.addRange(&_store, T.sizeof);
    }

    ~this()
    {
        assert(_store !is null);
        import core.memory : GC;
        GC.removeRange(&_store);
    }
}

void main()
{
    auto a = new RefCounted(0);
}
----

I don't know if there's anything wrong with this usage of GC.addRange/GC.removeRange. If there is, this is a bug in std.typecons.RefCounted. If there's not, it's a druntime/dmd issue.
Comment 3 Martin Nowak 2016-03-23 08:29:49 UTC

*** This issue has been marked as a duplicate of issue 15822 ***