Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poco::ClassLoader will crashed when DLL and EXE not use MD/MDd RunTime-Library #4549

Open
siren186 opened this issue May 8, 2024 · 6 comments
Labels

Comments

@siren186
Copy link

siren186 commented May 8, 2024

Describe the bug
Poco::Manifest class has STL member, It will crash if DLL and EXE use different Run-Time Library (MT/MD)

To Reproduce
Build options: VS2019 + debug_static_mt + x64
( It must be in debug mode and not MD if you wanna see the crash message box)

EXE code

#include "DLLTest/AbstractPlugin.h"

int wmain(int argc, wchar_t** argv)
{
    Poco::ClassLoader<AbstractPlugin> loader;
    loader.loadLibrary("Test.dll");
    AbstractPlugin* pPluginA = loader.create("PluginA");
    AbstractPlugin* pPluginB = loader.create("PluginB");

    loader.classFor("PluginA").autoDelete(pPluginA);
    delete pPluginB;
    loader.unloadLibrary("Test.dll");
}

DLL code

class AbstractPlugin
{
public:
    virtual ~AbstractPlugin() {};
    virtual void foo() const = 0;
};

class PluginA : public AbstractPlugin
{
public:
    virtual void foo() const override
    {
    }
};

class PluginB : public AbstractPlugin
{
public:
    virtual void foo() const override
    {
    }
};

POCO_BEGIN_MANIFEST(AbstractPlugin)
POCO_EXPORT_CLASS(PluginA)
POCO_EXPORT_CLASS(PluginB)
POCO_END_MANIFEST

Screenshots
PocoCrash

Please add relevant environment information:

  • Windows 10
  • POCO-1.13.2
@siren186 siren186 added the bug label May 8, 2024
@obiltschnig
Copy link
Member

You are not supposed to use different runtime libraries in your main application and your plugins.

@siren186
Copy link
Author

siren186 commented May 8, 2024

If I use MT to build DLL and EXE, it will crash, Because the STL container are malloc in DLL, but free in EXE

@siren186 siren186 changed the title Poco::ClassLoader will crashed when DLL and EXE use different Run-Time Library (MT/MD) Poco::ClassLoader will crashed when DLL and EXE not use MD/MDd RunTime-Library May 8, 2024
@obiltschnig
Copy link
Member

That's an unfortunate side effect of using MT with DLLs. Nothing we can do about it.

@siren186
Copy link
Author

siren186 commented May 8, 2024

What about hiding the implementation of Poco::Manifest::insert and Poco::Manifest::clear, to make sure who new, who delete, then it will not crash anymore.

@andrewauclair
Copy link
Contributor

What about hiding the implementation of Poco::Manifest::insert and Poco::Manifest::clear, to make sure who new, who delete, then it will not crash anymore.

That can't be done. Manifest is a templated class.

@siren186
Copy link
Author

That can't be done. Manifest is a templated class.

I wanna use POCO with CEF3 (https://github.com/chromiumembedded/cef),
But my CEF3 applications are building with MT.
I am using use my own plugin loader (https://github.com/siren186/z_com), It can work with different MT/MDs.
Now I wanna use POCO to instead, But it seems impossible

@aleks-f aleks-f removed the bug label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants