From: Iain Patterson Date: Sat, 18 Jan 2014 13:43:06 +0000 (+0000) Subject: Fixed regression in file browser. X-Git-Tag: v2.22~48 X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=914e07a1be72f036dbff709e5a29dc134e4042b9;p=nssm.git Fixed regression in file browser. The GUI file browser was the only place in the code we were using new and delete[] instead of HeapAlloc() and HeapFree(). The previous commit overlooked that fact and introduced a compiler error by assuming that lpstrFile was a buffer of a known size instead of being allocated with new. Fix the regression and use HeapAlloc()/HeapFree() for consistency. --- diff --git a/gui.cpp b/gui.cpp index 3f34943..2c20286 100644 --- a/gui.cpp +++ b/gui.cpp @@ -746,15 +746,17 @@ void browse(HWND window, TCHAR *current, unsigned long flags, ...) { va_end(arg); /* Remainder of the buffer is already zeroed */ } - ofn.lpstrFile = new TCHAR[PATH_LENGTH]; - if (flags & OFN_NOVALIDATE) { - /* Directory hack. */ - _sntprintf_s(ofn.lpstrFile, _countof(ofn.lpstrFile), _TRUNCATE, _T(":%s:"), message_string(NSSM_GUI_BROWSE_FILTER_DIRECTORIES)); - ofn.nMaxFile = DIR_LENGTH; - } - else { - _sntprintf_s(ofn.lpstrFile, _countof(ofn.lpstrFile), _TRUNCATE, _T("%s"), current); - ofn.nMaxFile = PATH_LENGTH; + ofn.lpstrFile = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, PATH_LENGTH * sizeof(TCHAR)); + if (ofn.lpstrFile) { + if (flags & OFN_NOVALIDATE) { + /* Directory hack. */ + _sntprintf_s(ofn.lpstrFile, PATH_LENGTH, _TRUNCATE, _T(":%s:"), message_string(NSSM_GUI_BROWSE_FILTER_DIRECTORIES)); + ofn.nMaxFile = DIR_LENGTH; + } + else { + _sntprintf_s(ofn.lpstrFile, PATH_LENGTH, _TRUNCATE, _T("%s"), current); + ofn.nMaxFile = PATH_LENGTH; + } } ofn.lpstrTitle = message_string(NSSM_GUI_BROWSE_TITLE); ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | flags; @@ -765,8 +767,7 @@ void browse(HWND window, TCHAR *current, unsigned long flags, ...) { SendMessage(window, WM_SETTEXT, 0, (LPARAM) ofn.lpstrFile); } if (ofn.lpstrFilter) HeapFree(GetProcessHeap(), 0, (void *) ofn.lpstrFilter); - - delete[] ofn.lpstrFile; + if (ofn.lpstrFile) HeapFree(GetProcessHeap(), 0, ofn.lpstrFile); } INT_PTR CALLBACK tab_dlg(HWND tab, UINT message, WPARAM w, LPARAM l) {