[llvm-branch-commits] [compiler-rt] release/18.x: [compiler-rt][profile] Fix InstrProfilingFile possible resource leak. (#81363) (PR #81402)
    via llvm-branch-commits 
    llvm-branch-commits at lists.llvm.org
       
    Sun Feb 11 00:25:25 PST 2024
    
    
  
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/81402
Backport 0a255fcf4a90f9e864ae9321b28e4956f7c865fb
Requested by: @devnexen
>From 9d41797f95e2bf60d335015eb749a65484e09995 Mon Sep 17 00:00:00 2001
From: David CARLIER <devnexen at gmail.com>
Date: Sat, 10 Feb 2024 19:14:28 +0000
Subject: [PATCH] [compiler-rt][profile] Fix InstrProfilingFile possible
 resource leak. (#81363)
close #79708
(cherry picked from commit 0a255fcf4a90f9e864ae9321b28e4956f7c865fb)
---
 compiler-rt/lib/profile/InstrProfilingFile.c | 3 +++
 1 file changed, 3 insertions(+)
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);
   }
 }
    
    
More information about the llvm-branch-commits
mailing list