Use a smart pointer to prevent Zap memory leak (#50425)
authorOmair Majid <omajid@redhat.com>
Sat, 3 Apr 2021 05:26:36 +0000 (01:26 -0400)
committerGitHub <noreply@github.com>
Sat, 3 Apr 2021 05:26:36 +0000 (22:26 -0700)
We allocate a Zap in CreatePDBWorker, but we never deallocate it.
Assuming the object instance is no longer needed, this fixes a memory
leak.

src/coreclr/zap/zapper.cpp

index 248e82e..c0d65d3 100644 (file)
@@ -121,8 +121,6 @@ STDAPI CreatePDBWorker(LPCWSTR pwzAssemblyPath, LPCWSTR pwzPlatformAssembliesPat
 
     BEGIN_ENTRYPOINT_NOTHROW;
 
-    Zapper* zap = NULL;
-
     EX_TRY
     {
         GetCompileInfo()->SetIsGeneratingNgenPDB(TRUE);
@@ -130,7 +128,7 @@ STDAPI CreatePDBWorker(LPCWSTR pwzAssemblyPath, LPCWSTR pwzPlatformAssembliesPat
         NGenOptions ngo = {0};
         ngo.dwSize = sizeof(NGenOptions);
 
-        zap = Zapper::NewZapper(&ngo);
+        NewHolder<Zapper> zap(Zapper::NewZapper(&ngo));
 
 #if !defined(FEATURE_MERGE_JIT_AND_ENGINE)
         zap->SetDontLoadJit();