wxWidgets crashs on Windows when load as DLL (Issue #24730)

17 views
Skip to first unread message

Xavier Wang

unread,
Jul 26, 2024, 2:49:11 AM (yesterday) Jul 26
to wx-...@googlegroups.com, Subscribed

Description

Bug description:

  1. load wx.dll with LoadLibraryA:
    image.png (view on web)

  2. unload dll with FreeLibrary

  3. call ExitProcess

Expected vs observed behaviour:

process crashs in nt.dll, RtlpFlsDataCleanup

Stack trace:

image.png (view on web)

Patch or snippet allowing to reproduce the problem:

minimal example:

example.zip

To Reproduce:

unzip the example.zip, and runs lua54.exe test.lua

Platform and version information

  • wxWidgets version you use: 3.2.5
  • wxWidgets port you use: wxMSW
  • OS and its version: Windows 10
    • GTK version:
    • Which GDK backend is used:
    • Desktop environment :
    • Current theme:


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24730@github.com>

VZ

unread,
Jul 26, 2024, 6:00:48 AM (yesterday) Jul 26
to wx-...@googlegroups.com, Subscribed

It would be really great to have a minimal example, e.g. not involving Lua. Please write a tiny program calling LoadLibrary() and FreeLibrary() from C if you can.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24730/2252406824@github.com>

PB

unread,
Jul 26, 2024, 9:26:04 AM (23 hours ago) Jul 26
to wx-...@googlegroups.com, Subscribed

AFAICT, this is not a wxWidgets DLL.

Firstly, the name: wx.dll. This does not match the wxWidgets DLL naming pattern.

Secondly, looking at the DLL details in Explorer shows it is a wxLua library:
wx-dll-lua.png (view on web)

Lastly, program Dependencies shows it does not export wxWidgets classes, only wxLua (e.g., wxLuaModuleApp) and it depends on lua54.dll.

All this means that you should report the issue to wxLua maintainers, not wxWidgets ones.

BTW, attempting to open this DLL in Dependency Walker (DW) makes DW freeze. I don't think I ever saw that with any other DLL (but I don't open that many in DW).


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24730/2252762790@github.com>

VZ

unread,
Jul 26, 2024, 9:28:23 AM (23 hours ago) Jul 26
to wx-...@googlegroups.com, Subscribed

Thanks, I didn't even realize wx.dll was the actuall DLL name and not a shortcut for "wxWidgets DLL".

We absolutely need a way to reproduce the problem using wx sources only, we can't do anything about any problems in DLLs that are not built by us.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24730/2252767269@github.com>

Xavier Wang

unread,
Jul 26, 2024, 9:56:30 AM (23 hours ago) Jul 26
to wx-...@googlegroups.com, Subscribed

Okay, I will try to build a pure wxWidgets DLL and a pure C program for it. Sorry for the noise from Lua binding (I'm noticing this
strange behavior when I trying to make a distro of some Lua bindings).


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24730/2252830848@github.com>

PB

unread,
Jul 26, 2024, 9:59:49 AM (23 hours ago) Jul 26
to wx-...@googlegroups.com, Subscribed

FWIW, running this code built with MSVS 2022 as 64-bit console application on Windows 10

#include <windows.h>

int main()
{
    HMODULE wxDLL = LoadLibraryW(L"wx.dll");

    if ( !wxDLL )
    {
        LPVOID msgBuf;
        DWORD  bufLen = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM ,
                                       nullptr, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&msgBuf, 0, nullptr);
        if ( bufLen )
        {
            MessageBoxW(nullptr, (LPCWSTR)msgBuf, L"ERROR", MB_OK | MB_ICONERROR);
            LocalFree(msgBuf);
        }
        else
        {
            MessageBoxW(nullptr, L"LoadLibrary(wx.dll) failed.", L"ERROR", MB_OK | MB_ICONERROR);
        }
    }
    else
    {
        FreeLibrary(wxDLL);
    }
}

produces only the message box with an error message The specified module could not be found (probably lua54.dll). This IMO further confirms that the issue is in the lua54.DLL (in its DllMain()?) and nothing do with wxWidgets itself.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24730/2252838356@github.com>

Xavier Wang

unread,
Jul 26, 2024, 10:14:35 AM (22 hours ago) Jul 26
to wx-...@googlegroups.com, Subscribed

@PBfordev I have tried this test program and it works well (I produced a lua54.dll for it). I think it's expected behavior. the wx.dll is from a Lua binding project for wxWidgets (wxLua).

The wxLua project static links the vs static libraries of wxWidgets and its binding code into one single dll, thus wx.dll.

When it loaded from Lua, it's luaopen_wx will be called, and some code runs. After that (I think) some fibers are created, but not freed when unload the DLL, so the ExitProcess tries to free them and accessed the freed DLL address space and cause the crash.

I will look into the luaopen_wx code and finding out what does it runs. And (maybe) report this bug to wxLua project.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24730/2252865637@github.com>

Xavier Wang

unread,
1:15 AM (7 hours ago) 1:15 AM
to wx-...@googlegroups.com, Subscribed

@vadz @PBfordev this is a real minimal example:
wx-test.zip

Runs host.exe to see the crash in ntdll.dll
to build it, change the wxdir in build.bat and run. the wxWidgets used built as:

mkdir wx-build && cd wx-build
cmake -DwxBUILD_USE_STATIC_RUNTIME=ON -DCMAKE_INSTALL_PREFIX=%CD%/../wx-dist ../wxWidgets-3.2.5
cmake --build . --config Release
cmake --install .


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24730/2253773088@github.com>

VZ

unread,
7:48 AM (1 hour ago) 7:48 AM
to wx-...@googlegroups.com, Subscribed

Is static runtime required to reproduce the problem?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/24730/2254126323@github.com>

Reply all
Reply to author
Forward
0 new messages