Skip to content

release/18.x: [compiler-rt][profile] Fix InstrProfilingFile possible resource leak. (#81363) #81402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2024

Conversation

llvmbot
Copy link
Member

@llvmbot llvmbot commented Feb 11, 2024

Backport 0a255fc

Requested by: @devnexen

@llvmbot llvmbot added this to the LLVM 18.X Release milestone Feb 11, 2024
@llvmbot
Copy link
Member Author

llvmbot commented Feb 11, 2024

@petrhosek What do you think about merging this PR to the release branch?

@llvmbot
Copy link
Member Author

llvmbot commented Feb 11, 2024

@llvm/pr-subscribers-pgo

Author: None (llvmbot)

Changes

Backport 0a255fc

Requested by: @devnexen


Full diff: https://github.com/llvm/llvm-project/pull/81402.diff

1 Files Affected:

  • (modified) compiler-rt/lib/profile/InstrProfilingFile.c (+3)
diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c
index 867ae73f0d3b27..f3b457d786e6bd 100644
--- a/compiler-rt/lib/profile/InstrProfilingFile.c
+++ b/compiler-rt/lib/profile/InstrProfilingFile.c
@@ -677,6 +677,7 @@ static void initializeProfileForContinuousMode(void) {
       PROF_ERR("Continuous counter sync mode is enabled, but raw profile is not"
                "page-aligned. CurrentFileOffset = %" PRIu64 ", pagesz = %u.\n",
                (uint64_t)CurrentFileOffset, PageSize);
+      fclose(File);
       return;
     }
     if (writeProfileWithFileObject(Filename, File) != 0) {
@@ -692,6 +693,8 @@ static void initializeProfileForContinuousMode(void) {
 
   if (doMerging()) {
     lprofUnlockFileHandle(File);
+  }
+  if (File != NULL) {
     fclose(File);
   }
 }

@petrhosek
Copy link
Member

@petrhosek What do you think about merging this PR to the release branch?

LGTM

@tstellar tstellar merged commit 390dcd4 into llvm:release/18.x Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-rt PGO Profile Guided Optimizations
Projects
Development

Successfully merging this pull request may close these issues.

4 participants