Unbreak "Duplicate session" on Windows, in a similar way to r7291.
[u/mdw/putty] / windows / window.c
index dca27a4..ceeaa76 100644 (file)
@@ -397,6 +397,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
            if (!cfg_launchable(&cfg) && !do_config()) {
                cleanup_exit(0);
            }
+           loaded_session = TRUE;     /* allow it to be launched directly */
        } else if (*p == '&') {
            /*
             * An initial & means we've been given a command line
@@ -412,6 +413,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
                cfg = *cp;
                UnmapViewOfFile(cp);
                CloseHandle(filemap);
+               loaded_session = TRUE;
            } else if (!do_config()) {
                cleanup_exit(0);
            }
@@ -539,7 +541,8 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
 
        cmdline_run_saved(&cfg);
 
-       if (!cfg_launchable(&cfg) && !do_config()) {
+       if ((!loaded_session || !cfg_launchable(&cfg)) &&
+           !do_config()) {
            cleanup_exit(0);
        }
 
@@ -816,9 +819,8 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
            sfree(handles);
            if (must_close_session)
                close_session();
-       }
-
-       sfree(handles);
+       } else
+           sfree(handles);
 
        while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
            if (msg.message == WM_QUIT)