Skip to content

Commit e4c7c73

Browse files
Goober5000claude
andauthored
null out editor-dialog globals on DestroyWindow (scp-fs2open#7512)
Several dialogs already null their global at the top of DestroyWindow, but a few do not: briefing, debriefing, event, background, message, cutscene, goal, and Fred_view_wnd. OnClose nulls in those five cover the user-initiated close path, but any teardown that bypasses OnClose leaves a dangling pointer that could be dereferenced. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5c110b5 commit e4c7c73

12 files changed

Lines changed: 44 additions & 8 deletions

fred2/bgbitmapdlg.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,13 @@ void bg_bitmap_dlg::OnCancel()
444444
OnClose();
445445
}
446446

447-
void bg_bitmap_dlg::OnClose()
447+
BOOL bg_bitmap_dlg::DestroyWindow()
448+
{
449+
Bg_bitmap_dialog = nullptr;
450+
return CDialog::DestroyWindow();
451+
}
452+
453+
void bg_bitmap_dlg::OnClose()
448454
{
449455
UpdateData(TRUE);
450456
Mission_palette = m_nebula_color;

fred2/bgbitmapdlg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class bg_bitmap_dlg : public CDialog
101101
// Overrides
102102
// ClassWizard generated virtual function overrides
103103
//{{AFX_VIRTUAL(bg_bitmap_dlg)
104+
public:
105+
virtual BOOL DestroyWindow();
104106
protected:
105107
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
106108
//}}AFX_VIRTUAL

fred2/briefingeditordlg.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,8 +1408,9 @@ void briefing_editor_dlg::OnEndlabeleditTree(NMHDR* pNMHDR, LRESULT* pResult)
14081408
*pResult = m_tree.end_label_edit(pTVDispInfo->item);
14091409
}
14101410

1411-
BOOL briefing_editor_dlg::DestroyWindow()
1411+
BOOL briefing_editor_dlg::DestroyWindow()
14121412
{
1413+
Briefing_dialog = nullptr;
14131414
m_play_bm.DeleteObject();
14141415
audiostream_close_file(m_voice_id, 0);
14151416
return CDialog::DestroyWindow();

fred2/debriefingeditordlg.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,9 @@ BOOL debriefing_editor_dlg::OnCommand(WPARAM wParam, LPARAM lParam)
498498
return CDialog::OnCommand(wParam, lParam);
499499
}
500500

501-
BOOL debriefing_editor_dlg::DestroyWindow()
501+
BOOL debriefing_editor_dlg::DestroyWindow()
502502
{
503+
Debriefing_dialog = nullptr;
503504
audiostream_close_file(m_voice_id, 0);
504505
m_play_bm.DeleteObject();
505506
return CDialog::DestroyWindow();

fred2/eventeditor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,8 +1520,10 @@ void event_editor::OnSelchangeWaveFilename()
15201520
update_persona();
15211521
}
15221522

1523-
BOOL event_editor::DestroyWindow()
1523+
BOOL event_editor::DestroyWindow()
15241524
{
1525+
Event_editor_dlg = nullptr;
1526+
15251527
audiostream_close_file(m_wave_id, 0);
15261528
m_wave_id = -1;
15271529

fred2/fredview.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5048,9 +5048,9 @@ void CFREDView::OnUpdateViewFullDetail(CCmdUI *pCmdUI)
50485048
pCmdUI->SetCheck(FullDetail);
50495049
}
50505050

5051-
BOOL CFREDView::DestroyWindow()
5051+
BOOL CFREDView::DestroyWindow()
50525052
{
5053-
// TODO: Add your specialized code here and/or call the base class
5053+
Fred_view_wnd = nullptr;
50545054
return CView::DestroyWindow();
50555055
}
50565056

fred2/messageeditordlg.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,13 @@ void CMessageEditorDlg::OnNew()
493493
update_cur_message();
494494
}
495495

496-
void CMessageEditorDlg::OnClose()
496+
BOOL CMessageEditorDlg::DestroyWindow()
497+
{
498+
Message_editor_dlg = nullptr;
499+
return CDialog::DestroyWindow();
500+
}
501+
502+
void CMessageEditorDlg::OnClose()
497503
{
498504
int z;
499505

fred2/messageeditordlg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class CMessageEditorDlg : public CDialog
4444
// Overrides
4545
// ClassWizard generated virtual function overrides
4646
//{{AFX_VIRTUAL(CMessageEditorDlg)
47+
public:
48+
virtual BOOL DestroyWindow();
4749
protected:
4850
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
4951
//}}AFX_VIRTUAL

fred2/missioncutscenesdlg.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,12 @@ void CMissionCutscenesDlg::OnCancel()
398398
CDialog::OnCancel();
399399
}
400400

401+
BOOL CMissionCutscenesDlg::DestroyWindow()
402+
{
403+
Cutscene_editor_dlg = nullptr;
404+
return CDialog::DestroyWindow();
405+
}
406+
401407
void CMissionCutscenesDlg::OnClose()
402408
{
403409
if (query_modified()) {

fred2/missioncutscenesdlg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class CMissionCutscenesDlg : public CDialog
5252
// Overrides
5353
// ClassWizard generated virtual function overrides
5454
//{{AFX_VIRTUAL(CMissionCutscenesDlg)
55+
public:
56+
virtual BOOL DestroyWindow();
5557
protected:
5658
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
5759
//}}AFX_VIRTUAL

0 commit comments

Comments
 (0)