Skip to content

Crash when callback is disconnected in a dll #78

Description

@JassJam

When using signals2 across multiple DDLs, everything works fine until the dlls gets unloaded, which results in crash the next time we dispatch the signal.
I found this stackoverflow post which describes the same issue i'm having.

The test sample:

Shared.cpp:

#include <boost/dll.hpp>
#include <boost/signals2.hpp>
#include <iostream>

struct SomeInterface
{
    boost::signals2::signal<void()> signal;
};

boost::signals2::connection con;

void init(SomeInterface* iface)
{
    con = iface->signal.connect([] { std::cout << "Hello, Shared!" << std::endl; });
}

void shutdown()
{
    con.disconnect();
}

BOOST_DLL_AUTO_ALIAS(init);
BOOST_DLL_AUTO_ALIAS(shutdown);

Host.cpp:

#include <boost/dll.hpp>
#include <boost/signals2.hpp>
#include <iostream>

struct SomeInterface
{
    boost::signals2::signal<void()> signal;
};

int main()
{
    SomeInterface* iface = new SomeInterface;

    {
        boost::dll::shared_library dll("Shared", boost::dll::load_mode::append_decorations);

        auto init     = dll.get<void (*)(SomeInterface*)>("init");
        auto shutdown = dll.get<void (*)()>("shutdown");

        init(iface);
        iface->signal();
        shutdown();
    }

    iface->signal();

    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions