From 29d4b054a804a2826b60e2777cd111dde1aac79f Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Thu, 24 Mar 2016 17:25:44 +0100 Subject: [PATCH] Fix crash on loading variant engine after changing variant The New Variant dialog did not store the variant name (and in fact several other option values, such as nick names) in allocated memory, but just by pointing to it, which made XBoard crash when the options were parsed again (as part of an engine load), and it tried to free() the old value. --- dialogs.c | 8 ++++---- winboard/woptions.c | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dialogs.c b/dialogs.c index 7ca879f..0216d64 100644 --- a/dialogs.c +++ b/dialogs.c @@ -546,7 +546,7 @@ Pick (int n) } gameInfo.variant = v; - appData.variant = VariantName(v); + ASSIGN(appData.variant, VariantName(v)); shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */ startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */ @@ -555,9 +555,9 @@ Pick (int n) appData.NrFiles = filesTmp; appData.holdingsSize = sizeTmp; appData.pieceToCharTable = NULL; - appData.pieceNickNames = ""; - appData.colorNickNames = ""; - appData.men = ""; + ASSIGN(appData.pieceNickNames, ""); + ASSIGN(appData.colorNickNames, ""); + ASSIGN(appData.men, ""); PopDown(TransientDlg); Reset(True, True); return; diff --git a/winboard/woptions.c b/winboard/woptions.c index 94b1ef5..34e3800 100644 --- a/winboard/woptions.c +++ b/winboard/woptions.c @@ -969,7 +969,7 @@ NewVariantDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) } gameInfo.variant = v; - appData.variant = VariantName(v); + ASSIGN(appData.variant, VariantName(v)); appData.NrFiles = (int) GetDlgItemInt(hDlg, IDC_Files, NULL, FALSE ); appData.NrRanks = (int) GetDlgItemInt(hDlg, IDC_Ranks, NULL, FALSE ); @@ -982,7 +982,9 @@ NewVariantDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) shuffleOpenings = FALSE; /* [HGM] shuffle: possible shuffle reset when we switch */ startedFromPositionFile = FALSE; /* [HGM] loadPos: no longer valid in new variant */ appData.pieceToCharTable = NULL; - appData.men = ""; + ASSIGN(appData.pieceNickNames, ""); + ASSIGN(appData.colorNickNames, ""); + ASSIGN(appData.men, ""); Reset(TRUE, TRUE); return TRUE; -- 1.7.0.4