Allocate a new console for stdin.
[nssm.git] / gui.cpp
diff --git a/gui.cpp b/gui.cpp
index 3f34943..694e0e2 100644 (file)
--- a/gui.cpp
+++ b/gui.cpp
@@ -161,7 +161,7 @@ int nssm_gui(int resource, nssm_service_t *service) {
     if (! service->rotate_bytes_high) SetDlgItemInt(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_BYTES_LOW, service->rotate_bytes_low, 0);\r
 \r
     /* Check if advanced settings are in use. */\r
-    if (service->stdout_disposition ^ service->stderr_disposition || service->stdout_disposition & ~CREATE_ALWAYS || service->stderr_disposition & ~CREATE_ALWAYS) popup_message(dlg, MB_OK | MB_ICONWARNING, NSSM_GUI_WARN_STDIO);\r
+    if (service->stdout_disposition != service->stderr_disposition || (service->stdout_disposition != NSSM_STDOUT_DISPOSITION && service->stdout_disposition != CREATE_ALWAYS) || (service->stderr_disposition != NSSM_STDERR_DISPOSITION && service->stderr_disposition != CREATE_ALWAYS)) popup_message(dlg, MB_OK | MB_ICONWARNING, NSSM_GUI_WARN_STDIO);\r
     if (service->rotate_bytes_high) popup_message(dlg, MB_OK | MB_ICONWARNING, NSSM_GUI_WARN_ROTATE_BYTES);\r
 \r
     /* Environment tab. */\r
@@ -746,15 +746,17 @@ void browse(HWND window, TCHAR *current, unsigned long flags, ...) {
     va_end(arg);\r
     /* Remainder of the buffer is already zeroed */\r
   }\r
-  ofn.lpstrFile = new TCHAR[PATH_LENGTH];\r
-  if (flags & OFN_NOVALIDATE) {\r
-    /* Directory hack. */\r
-    _sntprintf_s(ofn.lpstrFile, _countof(ofn.lpstrFile), _TRUNCATE, _T(":%s:"), message_string(NSSM_GUI_BROWSE_FILTER_DIRECTORIES));\r
-    ofn.nMaxFile = DIR_LENGTH;\r
-  }\r
-  else {
-    _sntprintf_s(ofn.lpstrFile, _countof(ofn.lpstrFile), _TRUNCATE, _T("%s"), current);\r
-    ofn.nMaxFile = PATH_LENGTH;\r
+  ofn.lpstrFile = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, PATH_LENGTH * sizeof(TCHAR));\r
+  if (ofn.lpstrFile) {
+    if (flags & OFN_NOVALIDATE) {\r
+      /* Directory hack. */\r
+      _sntprintf_s(ofn.lpstrFile, PATH_LENGTH, _TRUNCATE, _T(":%s:"), message_string(NSSM_GUI_BROWSE_FILTER_DIRECTORIES));\r
+      ofn.nMaxFile = DIR_LENGTH;\r
+    }\r
+    else {
+      _sntprintf_s(ofn.lpstrFile, PATH_LENGTH, _TRUNCATE, _T("%s"), current);\r
+      ofn.nMaxFile = PATH_LENGTH;\r
+    }
   }
   ofn.lpstrTitle = message_string(NSSM_GUI_BROWSE_TITLE);\r
   ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | flags;\r
@@ -765,8 +767,7 @@ void browse(HWND window, TCHAR *current, unsigned long flags, ...) {
     SendMessage(window, WM_SETTEXT, 0, (LPARAM) ofn.lpstrFile);\r
   }\r
   if (ofn.lpstrFilter) HeapFree(GetProcessHeap(), 0, (void *) ofn.lpstrFilter);\r
-\r
-  delete[] ofn.lpstrFile;\r
+  if (ofn.lpstrFile) HeapFree(GetProcessHeap(), 0, ofn.lpstrFile);
 }\r
 \r
 INT_PTR CALLBACK tab_dlg(HWND tab, UINT message, WPARAM w, LPARAM l) {\r