From b94dfac326be46cca0a0e019d132cb726c138a9e Mon Sep 17 00:00:00 2001 From: Alexandre Lissy Date: Mon, 12 Jan 2026 10:02:48 +0100 Subject: [PATCH] Enterprise: Check -felt for profile selection only on startup Doing it in SelectStartupProfile() was somehow hitting race condition leading to a segfault while running some tests, the stack including XPCOM version of it. --- toolkit/profile/nsToolkitProfileService.cpp | 34 --------------------- toolkit/xre/nsAppRunner.cpp | 34 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/toolkit/profile/nsToolkitProfileService.cpp b/toolkit/profile/nsToolkitProfileService.cpp index 9254698f71ad..94e872caee66 100644 --- a/toolkit/profile/nsToolkitProfileService.cpp +++ b/toolkit/profile/nsToolkitProfileService.cpp @@ -41,10 +41,6 @@ # include "mozilla/WidgetUtilsGtk.h" #endif -#if defined(MOZ_ENTERPRISE) -# include "mozilla/browser/extensions/felt/felt.h" -#endif - #include "nsAppDirectoryServiceDefs.h" #include "nsDirectoryServiceDefs.h" #include "nsNetCID.h" @@ -1560,36 +1556,6 @@ nsresult nsToolkitProfileService::SelectStartupProfile( return NS_OK; } -#if defined(MOZ_ENTERPRISE) - auto forcedProfile = geckoargs::sProfile.IsPresent(gArgc, gArgv); - if (is_felt_ui() && !forcedProfile) { - nsCOMPtr file; - MOZ_TRY( - GetSpecialSystemDirectory(OS_TemporaryDirectory, getter_AddRefs(file))); - MOZ_TRY(file->AppendNative("felt"_ns)); - - bool exists = false; - MOZ_TRY(file->Exists(&exists)); - - if (!exists) { - // Create a unique profile directory. This can fail if there are too many - // (thousands) of existing directories, which is unlikely to happen. - MOZ_TRY(file->CreateUnique(nsIFile::DIRECTORY_TYPE, 0700)); - } - - nsCOMPtr localDir = file; - file.forget(aRootDir); - localDir.forget(aLocalDir); - // Background tasks never use profiles known to the profile service. - *aProfile = nullptr; - - // consume -profile - (void)geckoargs::sProfile.Get(gArgc, gArgv); - - return NS_OK; - } -#endif - // Check the -profile command line argument. It accepts a single argument that // gives the path to use for the profile. ArgResult ar = CheckArg(*aArgc, aArgv, "profile", &arg); diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index 352570e1f4a2..550f90cce5d5 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -46,6 +46,7 @@ #if defined(MOZ_ENTERPRISE) # include "mozilla/browser/extensions/felt/felt.h" +# include "SpecialSystemDirectory.h" #endif #include "nsAppRunner.h" @@ -3118,6 +3119,39 @@ static nsresult SelectProfile(nsToolkitProfileService* aProfileSvc, return ShowProfileManager(aProfileSvc, aNative); } +#if defined(MOZ_ENTERPRISE) + { + auto forcedProfile = geckoargs::sProfile.IsPresent(gArgc, gArgv); + if (is_felt_ui() && !forcedProfile) { + nsCOMPtr file; + MOZ_TRY(GetSpecialSystemDirectory(OS_TemporaryDirectory, + getter_AddRefs(file))); + MOZ_TRY(file->AppendNative("felt"_ns)); + + bool exists = false; + MOZ_TRY(file->Exists(&exists)); + + if (!exists) { + // Create a unique profile directory. This can fail if there are too + // many (thousands) of existing directories, which is unlikely to + // happen. + MOZ_TRY(file->CreateUnique(nsIFile::DIRECTORY_TYPE, 0700)); + } + + nsCOMPtr localDir = file; + file.forget(aRootDir); + localDir.forget(aLocalDir); + // Background tasks never use profiles known to the profile service. + *aProfile = nullptr; + + // consume -profile + (void)geckoargs::sProfile.Get(gArgc, gArgv); + + return NS_OK; + } + } +#endif + // Ask the profile manager to select the profile directories to use. bool didCreate = false; rv = aProfileSvc->SelectStartupProfile(&gArgc, gArgv, gDoProfileReset,