Browse Source

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.
Iain Patterson 8 years ago
parent
commit
914e07a1be
1 changed files with 12 additions and 11 deletions
  1. 12 11
      gui.cpp

+ 12 - 11
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) {