Exit handler is not invoked for FreeCAD.exe
Created by: FedorNiskov
Describe the bug
The exit event handler is not invoked when FreeCAD.exe (the target GUI program) terminates. It terminates normally - as a result of closing the window with mouse-click.
(Sorry, I didn't know what keyword to use in the title, because this case doesn't match any keyword exactly.)
To Reproduce
We can use the following simple client to show the problem (compiled in the standard cmake way for DR):
#include <dr_api.h>
#include <stdio.h>
void event_exit() {
FILE *f = fopen("tmp", "a");
fprintf(f, "EXIT\n");
fclose(f);
}
DR_EXPORT void dr_client_main(client_id_t id, int argc, const char *argv[]) {
FILE *f = fopen("tmp", "a");
fprintf(f, "MAIN\n");
fclose(f);
dr_register_exit_event(event_exit);
}
Run this command, wait until the end of FreeCAD initialization, then close the window (drrun and freecad processes will finish):
drrun.exe -c client.dll -- FreeCAD.exe
After that, the tmp file contains "MAIN", but does not contain "EXIT".
Expected behavior
The exit handler must be called.
Versions
DynamoRIO - version 8.0.0-1 (binary release downloaded from the official website)
OS Windows 10 - version 20H2 (build 19042.804) This is a VirtualBox machine by Microsoft: https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/
FreeCAD 0.18.4 (x86-64) (installed by the installer from the official website) https://www.freecadweb.org https://github.com/FreeCAD/FreeCAD/releases/download/0.18.4/FreeCAD-0.18.4.980bf90-WIN-x64-installer.exe
Additional context
This problem is specific for FreeCAD; the exit handler is invoked normally for other targets (simple console programs or GUI programs, for example, Notepad).
I can see the problem even without any client - for example, using this command:
drrun.exe -debug -- FreeCAD.exe 1> output 2>&1
The output file content:
<Starting application C:\Program Files\FreeCAD 0.18\bin\FreeCAD.exe (1468)>
<cannot remove dll from rbtree: at root/min + can't find real tree>
<Running on newer-than-this-build "Microsoft Windows 10-2009 x64">
<Early threads found>
<Initial options = -no_dynamic_options -code_api -probe_api -stack_size 56K -max_elide_jmp 0 -max_elide_call 0 -no_inline_ignored_syscalls -native_exec_default_list '' -no_native_exec_managed_code -no_indcall2direct >
<curiosity: rex.w on OPSZ_6_irex10_short4!>
<Application changing protections of system memory at least once (0x00007ff983890000-0x00007ff983894000)>
<IPC ALERT WARNING: handle via IPC may mess up section-to-handle mapping>
<spurious rep/repne prefix @0x00007ff9837b0932 (f3 48 0f 1e ca): >
<proactive reset @ 248015 fragments>
FreeCAD 0.18, Libs: 0.18R4 (GitTag)
В© Juergen Riegel, Werner Mayer, Yorik van Havre 2001-2019
##### #### ### ####
# # # # # #
# ## #### #### # # # # #
#### # # # # # # # ##### # #
# # #### #### # # # # #
# # # # # # # # # ## ## ##
# # #### #### ### # # #### ## ## ##
It doesn't contain phrase <Stopping application ...> as for other applications.