fix(server): Prevent crash from dangling pointers in file dialog map

Fixed two bugs when closing ScreenSpyDlg with file transfer dialogs:

1. Access violation (0xC0000005): CDlgFileSend self-destructs via
   PostNcDestroy (delete this) when closed, leaving dangling pointers
   in m_FileRecvDlgs map.

2. Double-free: Original code called DestroyWindow() then delete,
   but DestroyWindow already triggers delete this via PostNcDestroy.

Solution:
- Store {HWND, pointer} pairs instead of raw pointers
- Check HWND validity with IsWindow() before accessing pointer
- Use SendMessage(WM_CLOSE) to let dialog self-destruct safely
- Always erase map entries to prevent accumulation of invalid data

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
yuanyuanxiangandClaude Opus 4.5 committed 2026-05-03 15:29:31 +02:00
1 parent 1df2a7b321
commit b732f841d0
2 files changed
+19 -8

No files matched your search

+2 -1
View File
@@ -198,7 +198,8 @@ public:
// 文件接收进度对话框(用于 Linux Ctrl+C -> 服务端 Ctrl+V)
// 按 transferID 管理多个并发传输
std::map<uint64_t, class CDlgFileSend*> m_FileRecvDlgs;
// 存储 {HWND, 指针} 对,HWND 用于安全检查(指针可能变成野指针)
std::map<uint64_t, std::pair<HWND, class CDlgFileSend*>> m_FileRecvDlgs;
void SaveSnapshot(void);
// 对话框数据