Skip to content

<functional>: Passing an object with an explicit alignment that owns a std::function by value leads to invalid free on x86 #964

@StephanTLavavej

Description

@StephanTLavavej

Repros with VS 2019 16.7 Preview 3.1. Specific to x86.

C:\Temp>type meow.cpp
#include <functional>
#include <stdio.h>

struct alignas(8) Overaligned
{
    std::function<void()> call;
};

static void SomeFunction(Overaligned over)
{
}

int main()
{
    printf("%zu\n", alignof(std::function<bool()>));
    printf("%zu\n", alignof(Overaligned));

    Overaligned ov;
    ov.call = [] {};
    SomeFunction(ov);
}

C:\Temp>ren meow.cpp totally_unique_name.cpp

C:\Temp>cl /EHsc /nologo /W4 /Od /MD totally_unique_name.cpp
totally_unique_name.cpp

C:\Temp>totally_unique_name
8
8
***CRASH***

I currently observe that the executable will crash for the first 3 times that I try to run it, then (without recompilation!) it will stop displaying the crash dialog. Renaming the source file to something unique and recompiling will repro the crash again. (Maybe Windows is detecting frequently-crashing executables and suppressing the Windows Error Reporting crash dialog?)

Different from GH-690.

Originally reported as DevCom-367683, also tracked by Microsoft-internal VSO-720596.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingexternalThis issue is unrelated to the STL

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions