desktop/source/app/updater.cxx |   59 ++++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 29 deletions(-)

New commits:
commit 8574d1af6f705afd108f64d608a5b580d51a88f6
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue May 27 18:34:44 2025 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sat May 31 21:49:42 2025 +0200

    Use vector to simplify memory management a bit
    
    Change-Id: I71665feb7da0a94ba35b1d46c5c90b634059ce70
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186085
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/desktop/source/app/updater.cxx b/desktop/source/app/updater.cxx
index 843c9b1e2fee..061d9ceebd81 100644
--- a/desktop/source/app/updater.cxx
+++ b/desktop/source/app/updater.cxx
@@ -158,7 +158,7 @@ OUString toStream(wchar_t const * s) { return 
OUString(o3tl::toU(s)); }
 #error "Need an implementation"
 #endif
 
-void createStr(const OUString& rStr, CharT** pArgs, size_t i)
+CharT* createStr(const OUString& rStr)
 {
 #ifdef UNX
     OString aStr = OUStringToOString(rStr, RTL_TEXTENCODING_UTF8);
@@ -170,34 +170,34 @@ void createStr(const OUString& rStr, CharT** pArgs, 
size_t i)
     CharT* pStr = new CharT[aStr.getLength() + 1];
     std::copy_n(aStr.getStr(), aStr.getLength(), pStr);
     pStr[aStr.getLength()] = '
-    pArgs[i] = pStr;
+    return pStr;
 }
 
-CharT** createCommandLine(OUString const & argv0)
+std::vector<CharT*> createCommandLine(OUString const & argv0)
 {
     OUString aInstallDir = Updater::getInstallationPath();
 
     size_t nCommandLineArgs = rtl_getAppCommandArgCount();
-    size_t nArgs = 8 + nCommandLineArgs;
-    CharT** pArgs = new CharT*[nArgs];
-    createStr(argv0, pArgs, 0);
+    std::vector<CharT*> aArgs;
+    aArgs.reserve(nCommandLineArgs + 8);
+    aArgs.push_back(createStr(argv0));
     {
         // directory with the patch log
         OUString aPatchDir = Updater::getPatchDirURL();
         rtl::Bootstrap::expandMacros(aPatchDir);
         OUString aTempDirPath = getPathFromURL(aPatchDir);
         Updater::log("Patch Dir: " + aTempDirPath);
-        createStr(aTempDirPath, pArgs, 1);
+        aArgs.push_back(createStr(aTempDirPath));
     }
     {
         // the actual update directory
         Updater::log("Install Dir: " + aInstallDir);
-        createStr(aInstallDir, pArgs, 2);
+        aArgs.push_back(createStr(aInstallDir));
     }
     {
         // the temporary updated build
         Updater::log("Working Dir: " + aInstallDir);
-        createStr(aInstallDir, pArgs, 3);
+        aArgs.push_back(createStr(aInstallDir));
     }
     {
 #ifdef UNX
@@ -210,20 +210,20 @@ CharT** createCommandLine(OUString const & argv0)
 #else
 #error "Need an implementation"
 #endif
-        createStr(aPID, pArgs, 4);
+        aArgs.push_back(createStr(aPID));
     }
     {
         OUString aExeDir = Updater::getExecutableDirURL();
         OUString aSofficePath = getPathFromURL(aExeDir);
         Updater::log("soffice Path: " + aSofficePath);
-        createStr(aSofficePath, pArgs, 5);
+        aArgs.push_back(createStr(aSofficePath));
     }
     {
         // the executable to start after the successful update
         OUString aExeDir = Updater::getExecutableDirURL();
         OUString aSofficePathURL = aExeDir + aSofficeExeName;
         OUString aSofficePath = getPathFromURL(aSofficePathURL);
-        createStr(aSofficePath, pArgs, 6);
+        aArgs.push_back(createStr(aSofficePath));
     }
 
     // add the command line arguments from the soffice list
@@ -231,12 +231,12 @@ CharT** createCommandLine(OUString const & argv0)
     {
         OUString aCommandLineArg;
         rtl_getAppCommandArg(i, &aCommandLineArg.pData);
-        createStr(aCommandLineArg, pArgs, 7 + i);
+        aArgs.push_back(createStr(aCommandLineArg));
     }
 
-    pArgs[nArgs - 1] = nullptr;
+    aArgs.push_back(nullptr);
 
-    return pArgs;
+    return aArgs;
 }
 
 struct update_file
@@ -303,7 +303,7 @@ bool update()
     OUString aUpdaterPath = getPathFromURL(aTempDirURL + "/" + aUpdaterName);
 
     Updater::log("Calling the updater with parameters: ");
-    CharT** pArgs = createCommandLine(aUpdaterPath);
+    std::vector<CharT*> aArgs = createCommandLine(aUpdaterPath);
 
     bool bSuccess = true;
     const char* pUpdaterTestReplace = std::getenv("LIBO_UPDATER_TEST_REPLACE");
@@ -311,30 +311,29 @@ bool update()
     {
 #if UNX
         OString aPath = OUStringToOString(aUpdaterPath, RTL_TEXTENCODING_UTF8);
-        if (execv(aPath.getStr(), pArgs))
+        if (execv(aPath.getStr(), aArgs.data()))
         {
             printf("execv failed with error %d %s
",errno,strerror(errno));
             bSuccess = false;
         }
 #elif defined(_WIN32)
-        bSuccess = WinLaunchChild(o3tl::toW(aUpdaterPath.getStr()), pArgs);
+        bSuccess = WinLaunchChild(o3tl::toW(aUpdaterPath.getStr()), 
aArgs.data());
 #endif
     }
     else
     {
         SAL_WARN("desktop.updater", "Updater executable path: " << 
aUpdaterPath);
-        for (size_t i = 0; i < 8 + rtl_getAppCommandArgCount(); ++i)
+        for (auto arg : aArgs)
         {
-            SAL_WARN("desktop.updater", toStream(pArgs[i]));
+            SAL_WARN("desktop.updater", toStream(arg));
         }
         bSuccess = false;
     }
 
-    for (size_t i = 0; i < 8 + rtl_getAppCommandArgCount(); ++i)
+    for (auto arg : aArgs)
     {
-        delete[] pArgs[i];
+        delete[] arg;
     }
-    delete[] pArgs;
 
     return bSuccess;
 }
commit b3ed03053d9c304c640fba7442f3278543475852
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue May 27 13:47:39 2025 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sat May 31 21:49:32 2025 +0200

    Don't throw on failure copying updater, just return false
    
    This is not a fatal error; other failures are handled in update()
    gracefully. The exception generated here would crash the program,
    because it's not caught.
    
    Change-Id: Id4faa7eed3abacaf075d16f9ec13d61af873121a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186082
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/desktop/source/app/updater.cxx b/desktop/source/app/updater.cxx
index 2dd39ad1f1c7..843c9b1e2fee 100644
--- a/desktop/source/app/updater.cxx
+++ b/desktop/source/app/updater.cxx
@@ -120,7 +120,7 @@ OUString normalizePath(const OUString& rPath)
     return aPath;
 }
 
-void CopyFileToDir(const OUString& rTempDirURL, const OUString & rFileName, 
const OUString& rOldDir)
+bool CopyFileToDir(const OUString& rTempDirURL, const OUString & rFileName, 
const OUString& rOldDir)
 {
     OUString aSourceURL = rOldDir + "/" + rFileName;
     OUString aDestURL = rTempDirURL + "/" + rFileName;
@@ -129,8 +129,9 @@ void CopyFileToDir(const OUString& rTempDirURL, const 
OUString & rFileName, cons
     if (eError != osl::File::E_None)
     {
         SAL_WARN("desktop.updater", "could not copy the file to a temp 
directory: " << rFileName);
-        throw std::exception();
+        return false;
     }
+    return true;
 }
 
 OUString getPathFromURL(const OUString& rURL)
@@ -141,10 +142,10 @@ OUString getPathFromURL(const OUString& rURL)
     return normalizePath(aPath);
 }
 
-void CopyUpdaterToTempDir(const OUString& rInstallDirURL, const OUString& 
rTempDirURL)
+bool CopyUpdaterToTempDir(const OUString& rInstallDirURL, const OUString& 
rTempDirURL)
 {
-    CopyFileToDir(rTempDirURL, aUpdaterName, rInstallDirURL);
-    CopyFileToDir(rTempDirURL, u"updater.ini"_ustr, rInstallDirURL);
+    return CopyFileToDir(rTempDirURL, aUpdaterName, rInstallDirURL)
+           && CopyFileToDir(rTempDirURL, u"updater.ini"_ustr, rInstallDirURL);
 }
 
 #ifdef UNX
@@ -296,7 +297,8 @@ bool update()
 {
     utl::TempFileNamed aTempDir(nullptr, true);
     OUString aTempDirURL = aTempDir.GetURL();
-    CopyUpdaterToTempDir(Updater::getExecutableDirURL(), aTempDirURL);
+    if (!CopyUpdaterToTempDir(Updater::getExecutableDirURL(), aTempDirURL))
+        return false;
 
     OUString aUpdaterPath = getPathFromURL(aTempDirURL + "/" + aUpdaterName);
 

Reply via email to