comphelper/source/windows/windows_process.cxx                 |    8 ++------
 desktop/win32/source/QuickStart/QuickStart.cxx                |    7 +++----
 desktop/win32/source/applauncher/launcher.cxx                 |    2 +-
 desktop/win32/source/loader.cxx                               |    7 ++-----
 extensions/source/scanner/scanwin.cxx                         |    3 +--
 pyuno/zipcore/python.cxx                                      |    4 +---
 sal/osl/w32/procimpl.cxx                                      |    9 +++++----
 setup_native/source/win32/customactions/reg_dlls/reg_dlls.cxx |    4 ++--
 shell/source/win32/spsupp/COMOpenDocuments.cxx                |    5 +----
 shell/source/win32/spsupp/spsuppHelper.cxx                    |    5 +----
 vcl/win/app/salinst.cxx                                       |    3 +--
 11 files changed, 20 insertions(+), 37 deletions(-)

New commits:
commit e143c83b1c5a6479562adaed0086923c568d90cf
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Jan 8 09:58:22 2025 +0100
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Jan 8 11:37:08 2025 +0100

    Simplify using designated initializers
    
    Change-Id: I73d666a0aa4a41e8e73cb701161be1da6fd59d0d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179942
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/comphelper/source/windows/windows_process.cxx 
b/comphelper/source/windows/windows_process.cxx
index 8e7fd19f0b30..fc91145bbbf2 100644
--- a/comphelper/source/windows/windows_process.cxx
+++ b/comphelper/source/windows/windows_process.cxx
@@ -179,12 +179,8 @@ WinLaunchChild(const wchar_t *exePath,
         return FALSE;
     }
 
-    STARTUPINFOW si;
-    std::memset(&si, 0, sizeof si);
-    si.cb = sizeof(STARTUPINFOW);
-    si.lpDesktop = const_cast<LPWSTR>(L"winsta0\Default");
-    PROCESS_INFORMATION pi;
-    std::memset(&pi, 0, sizeof pi);
+    STARTUPINFOW si{ .cb = sizeof(si), .lpDesktop = 
const_cast<LPWSTR>(L"winsta0\Default") };
+    PROCESS_INFORMATION pi{};
 
     if (userToken == nullptr)
     {
diff --git a/desktop/win32/source/QuickStart/QuickStart.cxx 
b/desktop/win32/source/QuickStart/QuickStart.cxx
index 707f60341823..4ea17f705368 100644
--- a/desktop/win32/source/QuickStart/QuickStart.cxx
+++ b/desktop/win32/source/QuickStart/QuickStart.cxx
@@ -59,10 +59,7 @@ static bool launchSoffice( )
         imagename[_MAX_PATH] = 0;
         _snwprintf(imagename, _MAX_PATH, L"\"%s\" --quickstart", filename );
 
-        STARTUPINFOW aStartupInfo;
-        ZeroMemory(&aStartupInfo, sizeof(aStartupInfo));
-        aStartupInfo.cb = sizeof(aStartupInfo);
-        aStartupInfo.wShowWindow = SW_SHOW;
+        STARTUPINFOW aStartupInfo{ .cb = sizeof(aStartupInfo), .wShowWindow = 
SW_SHOW };
         PROCESS_INFORMATION aProcessInfo;
         bool bSuccess = CreateProcessW(filename, imagename, nullptr, nullptr, 
TRUE, 0, nullptr, nullptr, &aStartupInfo, &aProcessInfo);
         if ( !bSuccess )
diff --git a/desktop/win32/source/applauncher/launcher.cxx 
b/desktop/win32/source/applauncher/launcher.cxx
index 1ec8caf13555..ab5725214ef5 100644
--- a/desktop/win32/source/applauncher/launcher.cxx
+++ b/desktop/win32/source/applauncher/launcher.cxx
@@ -29,7 +29,7 @@ extern "C" int APIENTRY wWinMain( HINSTANCE, HINSTANCE, 
LPWSTR, int )
 {
     // Retrieve startup info
 
-    STARTUPINFOW aStartupInfo{ sizeof(aStartupInfo) };
+    STARTUPINFOW aStartupInfo{ .cb = sizeof(aStartupInfo) };
     GetStartupInfoW( &aStartupInfo );
 
     // Retrieve command line
diff --git a/desktop/win32/source/loader.cxx b/desktop/win32/source/loader.cxx
index 3e306dbdd70c..4246f3f7b7c2 100644
--- a/desktop/win32/source/loader.cxx
+++ b/desktop/win32/source/loader.cxx
@@ -206,9 +206,7 @@ int officeloader_impl(bool bAllowConsole)
 {
     const auto& [szTargetFileName, szIniDirectory] = extendLoaderEnvironment();
 
-    STARTUPINFOW aStartupInfo;
-    ZeroMemory(&aStartupInfo, sizeof(aStartupInfo));
-    aStartupInfo.cb = sizeof(aStartupInfo);
+    STARTUPINFOW aStartupInfo{ .cb = sizeof(aStartupInfo) };
 
     // Create process with same command line, environment and stdio handles 
which
     // are directed to the created pipes
@@ -380,8 +378,7 @@ int unopkgloader_impl(bool bAllowConsole)
 {
     const auto& [szTargetFileName, szIniDirectory] = extendLoaderEnvironment();
 
-    STARTUPINFOW aStartupInfo{};
-    aStartupInfo.cb = sizeof(aStartupInfo);
+    STARTUPINFOW aStartupInfo{ .cb = sizeof(aStartupInfo) };
     GetStartupInfoW(&aStartupInfo);
 
     DWORD   dwExitCode = DWORD(-1);
diff --git a/extensions/source/scanner/scanwin.cxx 
b/extensions/source/scanner/scanwin.cxx
index 198b092846cd..933531526f7a 100644
--- a/extensions/source/scanner/scanwin.cxx
+++ b/extensions/source/scanner/scanwin.cxx
@@ -264,8 +264,7 @@ void Twain::ShimListenerThread::execute()
             // We need a WinAPI HANDLE of the process to be able to wait on it 
and detect the process
             // termination; so use WinAPI to start the process, not 
osl_executeProcess.
 
-            STARTUPINFOW si{};
-            si.cb = sizeof(si);
+            STARTUPINFOW si{ .cb = sizeof(si) };
             PROCESS_INFORMATION pi;
 
             if (!CreateProcessW(nullptr, 
const_cast<LPWSTR>(o3tl::toW(sCmdLine.getStr())), nullptr,
diff --git a/pyuno/zipcore/python.cxx b/pyuno/zipcore/python.cxx
index 77c2e0031b61..a65067bf3509 100644
--- a/pyuno/zipcore/python.cxx
+++ b/pyuno/zipcore/python.cxx
@@ -189,9 +189,7 @@ int wmain(int argc, wchar_t ** argv, wchar_t **) {
             exit(EXIT_FAILURE);
         }
     }
-    STARTUPINFOW startinfo;
-    ZeroMemory(&startinfo, sizeof (STARTUPINFOW));
-    startinfo.cb = sizeof (STARTUPINFOW);
+    STARTUPINFOW startinfo{ .cb = sizeof(startinfo) };
     PROCESS_INFORMATION procinfo;
     if (!CreateProcessW(
             pythonexe.data(), cl, nullptr, nullptr, FALSE, 
CREATE_UNICODE_ENVIRONMENT, nullptr,
diff --git a/sal/osl/w32/procimpl.cxx b/sal/osl/w32/procimpl.cxx
index d271c391eed7..1af2a45eeaf6 100644
--- a/sal/osl/w32/procimpl.cxx
+++ b/sal/osl/w32/procimpl.cxx
@@ -467,10 +467,9 @@ oslProcessError SAL_CALL 
osl_executeProcess_WithRedirectedIO(
     if ((Options & osl_Process_DETACHED) && !(flags & CREATE_NEW_CONSOLE))
         flags |= DETACHED_PROCESS;
 
-    STARTUPINFOW startup_info = {};
-    startup_info.cb        = sizeof(startup_info);
-    startup_info.dwFlags   = STARTF_USESHOWWINDOW;
-    startup_info.lpDesktop = const_cast<LPWSTR>(L"");
+    STARTUPINFOW startup_info{ .cb = sizeof(startup_info),
+                               .lpDesktop = const_cast<LPWSTR>(L""),
+                               .dwFlags = STARTF_USESHOWWINDOW };
 
     /* Create pipes for redirected IO */
     HANDLE hInputRead  = nullptr;
diff --git a/setup_native/source/win32/customactions/reg_dlls/reg_dlls.cxx 
b/setup_native/source/win32/customactions/reg_dlls/reg_dlls.cxx
index 8231e3c5e3cb..cc0d8b74c5b4 100644
--- a/setup_native/source/win32/customactions/reg_dlls/reg_dlls.cxx
+++ b/setup_native/source/win32/customactions/reg_dlls/reg_dlls.cxx
@@ -162,8 +162,7 @@ void RegDLL(MSIHANDLE hInst, const std::wstring& sArgs, 
bool bUnreg)
         sCmd += sArgs;
         WriteLog(hInst, "Prepared regsvr32 command:", sCmd);
 
-        STARTUPINFOW si{};
-        si.cb = sizeof(si);
+        STARTUPINFOW si{ .cb = sizeof(si) };
         PROCESS_INFORMATION pi{};
         if (!CreateProcessW(sRegSvr32.c_str(), 
const_cast<LPWSTR>(sCmd.c_str()), nullptr, nullptr,
                             FALSE, CREATE_NO_WINDOW, nullptr, nullptr, &si, 
&pi))
diff --git a/shell/source/win32/spsupp/COMOpenDocuments.cxx 
b/shell/source/win32/spsupp/COMOpenDocuments.cxx
index 87a61691d476..701deef38f50 100644
--- a/shell/source/win32/spsupp/COMOpenDocuments.cxx
+++ b/shell/source/win32/spsupp/COMOpenDocuments.cxx
@@ -26,10 +26,7 @@ HRESULT LOStart(Args... args)
     std::wstring sCmdLine((quote(GetHelperExe()) + ... + (L" " + 
quote(args))));
     LPWSTR pCmdLine = const_cast<LPWSTR>(sCmdLine.c_str());
 
-    STARTUPINFOW si = {};
-    si.cb = sizeof si;
-    si.dwFlags = STARTF_USESHOWWINDOW;
-    si.wShowWindow = SW_SHOW;
+    STARTUPINFOW si{ .cb = sizeof(si), .dwFlags = STARTF_USESHOWWINDOW, 
.wShowWindow = SW_SHOW };
     PROCESS_INFORMATION pi = {};
     if (!CreateProcessW(nullptr, pCmdLine, nullptr, nullptr, FALSE, 0, 
nullptr, nullptr, &si, &pi))
         return HRESULT_FROM_WIN32(GetLastError());
diff --git a/shell/source/win32/spsupp/spsuppHelper.cxx 
b/shell/source/win32/spsupp/spsuppHelper.cxx
index 5867a5ea393d..88d2ccf19485 100644
--- a/shell/source/win32/spsupp/spsuppHelper.cxx
+++ b/shell/source/win32/spsupp/spsuppHelper.cxx
@@ -126,10 +126,7 @@ DWORD LOStart(const wchar_t* sModeArg, const wchar_t* 
sFilePath)
                         + o3tl::toU(sFilePath) + "\"";
     LPWSTR pCmdLine = const_cast<LPWSTR>(o3tl::toW(sCmdLine.getStr()));
 
-    STARTUPINFOW si = {};
-    si.cb = sizeof si;
-    si.dwFlags = STARTF_USESHOWWINDOW;
-    si.wShowWindow = SW_SHOW;
+    STARTUPINFOW si{ .cb = sizeof(si), .dwFlags = STARTF_USESHOWWINDOW, 
.wShowWindow = SW_SHOW };
     PROCESS_INFORMATION pi{};
     if (!CreateProcessW(nullptr, pCmdLine, nullptr, nullptr, FALSE, 0, 
nullptr, nullptr, &si, &pi))
     {
diff --git a/vcl/win/app/salinst.cxx b/vcl/win/app/salinst.cxx
index 3dad25b4da62..a5812bfdf30c 100644
--- a/vcl/win/app/salinst.cxx
+++ b/vcl/win/app/salinst.cxx
@@ -332,8 +332,7 @@ VCLPLUG_WIN_PUBLIC SalInstance* create_SalInstance()
 {
     SalData* pSalData = new SalData();
 
-    STARTUPINFOW aSI;
-    aSI.cb = sizeof( aSI );
+    STARTUPINFOW aSI{ .cb = sizeof(aSI) };
     GetStartupInfoW( &aSI );
     pSalData->mhInst = GetModuleHandleW( nullptr );
     pSalData->mnCmdShow = aSI.wShowWindow;
commit f468593d901b9f4ad8e90b6e101d17e6d490b5ef
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Jan 8 09:51:25 2025 +0100
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Jan 8 11:37:01 2025 +0100

    Close handles properly
    
    Change-Id: If8620229d41ae9b6c0a1714967a8bb6d51d3ba0d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179939
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/desktop/win32/source/QuickStart/QuickStart.cxx 
b/desktop/win32/source/QuickStart/QuickStart.cxx
index 3277a6abfe5a..707f60341823 100644
--- a/desktop/win32/source/QuickStart/QuickStart.cxx
+++ b/desktop/win32/source/QuickStart/QuickStart.cxx
@@ -68,6 +68,8 @@ static bool launchSoffice( )
         if ( !bSuccess )
             return false;
 
+        CloseHandle(aProcessInfo.hProcess);
+        CloseHandle(aProcessInfo.hThread);
         return true;
     }
     else
diff --git a/sal/osl/w32/procimpl.cxx b/sal/osl/w32/procimpl.cxx
index f36a3c90b073..d271c391eed7 100644
--- a/sal/osl/w32/procimpl.cxx
+++ b/sal/osl/w32/procimpl.cxx
@@ -576,6 +576,8 @@ oslProcessError SAL_CALL 
osl_executeProcess_WithRedirectedIO(
 
             return osl_Process_E_None;
         }
+        else
+            CloseHandle(process_info.hProcess);
     }
 
     /* if an error occurred we have to close the server side pipe ends too */
diff --git a/setup_native/source/win32/customactions/reg_dlls/reg_dlls.cxx 
b/setup_native/source/win32/customactions/reg_dlls/reg_dlls.cxx
index b1e204a80d12..8231e3c5e3cb 100644
--- a/setup_native/source/win32/customactions/reg_dlls/reg_dlls.cxx
+++ b/setup_native/source/win32/customactions/reg_dlls/reg_dlls.cxx
@@ -168,6 +168,7 @@ void RegDLL(MSIHANDLE hInst, const std::wstring& sArgs, 
bool bUnreg)
         if (!CreateProcessW(sRegSvr32.c_str(), 
const_cast<LPWSTR>(sCmd.c_str()), nullptr, nullptr,
                             FALSE, CREATE_NO_WINDOW, nullptr, nullptr, &si, 
&pi))
             ThrowLastError("CreateProcessW");
+        CloseHandle(pi.hThread);
         auto aCloseProcHandleGuard(Guard(pi.hProcess));
         WriteLog(hInst, "CreateProcessW succeeded");
 

Reply via email to