[llvm] Fix memory leak in Offloading API (PR #161430)

David Salinas via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 30 13:35:20 PDT 2025


https://github.com/david-salinas updated https://github.com/llvm/llvm-project/pull/161430

>From aa234bf11b661d960d47368ef9de61641ceebd56 Mon Sep 17 00:00:00 2001
From: david-salinas <dsalinas at amd.com>
Date: Tue, 30 Sep 2025 19:34:29 +0000
Subject: [PATCH 1/2] Fix memory leak in Offloading API

---
 llvm/lib/Object/OffloadBundle.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Object/OffloadBundle.cpp b/llvm/lib/Object/OffloadBundle.cpp
index 0dd378e65fd81..7c84e9b92032d 100644
--- a/llvm/lib/Object/OffloadBundle.cpp
+++ b/llvm/lib/Object/OffloadBundle.cpp
@@ -120,14 +120,14 @@ OffloadBundleFatBin::create(MemoryBufferRef Buf, uint64_t SectionOffset,
   if (identify_magic(Buf.getBuffer()) != file_magic::offload_bundle)
     return errorCodeToError(object_error::parse_failed);
 
-  OffloadBundleFatBin *TheBundle = new OffloadBundleFatBin(Buf, FileName);
+  std::unique_ptr<OffloadBundleFatBin> TheBundle(new OffloadBundleFatBin(Buf, FileName));
 
   // Read the Bundle Entries
   Error Err = TheBundle->readEntries(Buf.getBuffer(), SectionOffset);
   if (Err)
     return Err;
 
-  return std::unique_ptr<OffloadBundleFatBin>(TheBundle);
+  return TheBundle;
 }
 
 Error OffloadBundleFatBin::extractBundle(const ObjectFile &Source) {

>From 341f10dfc19a84dfed45d97e4d9c2873d76069dd Mon Sep 17 00:00:00 2001
From: david-salinas <dsalinas at amd.com>
Date: Tue, 30 Sep 2025 20:34:53 +0000
Subject: [PATCH 2/2] fix clang-format errors

---
 llvm/lib/Object/OffloadBundle.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Object/OffloadBundle.cpp b/llvm/lib/Object/OffloadBundle.cpp
index 7c84e9b92032d..a6a9628acddcc 100644
--- a/llvm/lib/Object/OffloadBundle.cpp
+++ b/llvm/lib/Object/OffloadBundle.cpp
@@ -120,7 +120,8 @@ OffloadBundleFatBin::create(MemoryBufferRef Buf, uint64_t SectionOffset,
   if (identify_magic(Buf.getBuffer()) != file_magic::offload_bundle)
     return errorCodeToError(object_error::parse_failed);
 
-  std::unique_ptr<OffloadBundleFatBin> TheBundle(new OffloadBundleFatBin(Buf, FileName));
+  std::unique_ptr<OffloadBundleFatBin> TheBundle(
+      new OffloadBundleFatBin(Buf, FileName));
 
   // Read the Bundle Entries
   Error Err = TheBundle->readEntries(Buf.getBuffer(), SectionOffset);



More information about the llvm-commits mailing list