Added check for GetManagedCommandLine() returning a nullptr in ProfileDataAllocateSce...
authorBrian Sullivan <briansul@microsoft.com>
Fri, 26 Apr 2019 23:59:03 +0000 (16:59 -0700)
committerBrian Sullivan <briansul@microsoft.com>
Fri, 26 Apr 2019 23:59:03 +0000 (16:59 -0700)
Moved call to ReleaseManagedCommandLine() to EEShutDownHelper

Commit migrated from https://github.com/dotnet/coreclr/commit/d360e7cb82d2b0bcec37fc9d06bb88fe7d87e2ae

src/coreclr/src/vm/ceeload.cpp
src/coreclr/src/vm/ceemain.cpp
src/coreclr/src/vm/corhost.cpp

index ab5d6e8..c21f186 100644 (file)
@@ -11779,6 +11779,13 @@ static void ProfileDataAllocateScenarioInfo(ProfileEmitter * pEmitter, LPCSTR sc
         // Get the managed command line.
         LPCWSTR pCmdLine = GetManagedCommandLine();
 
+        // If this process started as a service we won't havre a managed command line
+        if (pCmdLine == nullptr)
+        {
+            // Use the result from GetCommandLineW() instead
+            pCmdLine = GetCommandLineW();
+        }
+
         S_SIZE_T cCmdLine = S_SIZE_T(wcslen(pCmdLine));
         cCmdLine += 1;
         if (cCmdLine.IsOverflow())
index e595e88..d2e23b8 100644 (file)
@@ -1463,6 +1463,12 @@ void STDMETHODCALLTYPE EEShutDownHelper(BOOL fIsDllUnloading)
     DiagnosticServer::Shutdown();
 #endif // FEATURE_PERFTRACING
 
+    // When running under FEATURE_PAL, the SetCommandLineArgs call above will
+    // call SaveManagedCommandLine which will allocate memory using new WCHAR[]
+    // We can release this memory now.
+    //
+    ReleaseManagedCommandLine();
+
 #if defined(FEATURE_COMINTEROP)
     // Get the current thread.
     Thread * pThisThread = GetThread();
index c588e31..cbba60d 100644 (file)
@@ -468,12 +468,6 @@ HRESULT CorHost2::ExecuteAssembly(DWORD dwAppDomainId,
         }
 
         GCPROTECT_END();
-
-        // When running under FEATURE_PAL, the SetCommandLineArgs call above will
-        // call SaveManagedCommandLine which will allocate memory using new WCHAR[]
-        // We can release this memory now.
-        //
-        ReleaseManagedCommandLine();
     }
 
     UNINSTALL_UNWIND_AND_CONTINUE_HANDLER;