[llvm] [llvm][Support] Put back filename into FileToRemoveList (PR #124065)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 22 20:53:10 PST 2025
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/124065
Prevents avoidable memory leaks.
Looks like exchange added in aa1333a91f8d8a060bcf5b14aa32a6e8bab74e8c didn't
take "continue" into account.
>From 6c834261e2e9881869678c3c4ed5f786772ac907 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Wed, 22 Jan 2025 20:53:01 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
---
llvm/lib/Support/Unix/Signals.inc | 34 +++++++++++++++++--------------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc
index 330b5d26fa50be..9a12663228a368 100644
--- a/llvm/lib/Support/Unix/Signals.inc
+++ b/llvm/lib/Support/Unix/Signals.inc
@@ -149,6 +149,24 @@ public:
}
}
+ static void removeFile(char *path) {
+ // Get the status so we can determine if it's a file or directory. If we
+ // can't stat the file, ignore it.
+ struct stat buf;
+ if (stat(path, &buf) != 0)
+ return;
+
+ // If this is not a regular file, ignore it. We want to prevent removal
+ // of special files like /dev/null, even if the compiler is being run
+ // with the super-user permissions.
+ if (!S_ISREG(buf.st_mode))
+ return;
+
+ // Otherwise, remove the file. We ignore any errors here as there is
+ // nothing else we can do.
+ unlink(path);
+ }
+
// Signal-safe.
static void removeAllFiles(std::atomic<FileToRemoveList *> &Head) {
// If cleanup were to occur while we're removing files we'd have a bad time.
@@ -162,21 +180,7 @@ public:
// If erasing was occuring while we're trying to remove files we'd look
// at free'd data. Take away the path and put it back when done.
if (char *path = currentFile->Filename.exchange(nullptr)) {
- // Get the status so we can determine if it's a file or directory. If we
- // can't stat the file, ignore it.
- struct stat buf;
- if (stat(path, &buf) != 0)
- continue;
-
- // If this is not a regular file, ignore it. We want to prevent removal
- // of special files like /dev/null, even if the compiler is being run
- // with the super-user permissions.
- if (!S_ISREG(buf.st_mode))
- continue;
-
- // Otherwise, remove the file. We ignore any errors here as there is
- // nothing else we can do.
- unlink(path);
+ removeFile(path);
// We're done removing the file, erasing can safely proceed.
currentFile->Filename.exchange(path);
More information about the llvm-commits
mailing list