Skip to content

[lldb] Cleanup dyld_process_t after constructing SharedCacheInfo #106157

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
Aug 27, 2024

Conversation

bulbazord
Copy link
Member

Without calling dyld_process_dispose, LLDB will leak the memory associated with the dyld_process_t.

rdar://134738265

Without calling `dyld_process_dispose`, LLDB will leak the memory
associated with the `dyld_process_t`.

rdar://134738265
@llvmbot
Copy link
Member

llvmbot commented Aug 26, 2024

@llvm/pr-subscribers-lldb

Author: Alex Langford (bulbazord)

Changes

Without calling dyld_process_dispose, LLDB will leak the memory associated with the dyld_process_t.

rdar://134738265


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

1 Files Affected:

  • (modified) lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm (+4-1)
diff --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
index d27bd1b7426e6c..6e924fdc684cfe 100644
--- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
+++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
@@ -650,12 +650,15 @@ static bool ResolveAndVerifyCandidateSupportDir(FileSpec &path) {
   if (!dyld_process)
     return false;
 
+  auto cleanup_process_on_exit =
+      llvm::make_scope_exit([&]() { dyld_process_dispose(dyld_process); });
+
   dyld_process_snapshot_t snapshot =
       dyld_process_snapshot_create_for_process(dyld_process, nullptr);
   if (!snapshot)
     return false;
 
-  auto on_exit =
+  auto cleanup_snapshot_on_exit =
       llvm::make_scope_exit([&]() { dyld_process_snapshot_dispose(snapshot); });
 
   dyld_shared_cache_t shared_cache =

Copy link
Collaborator

@jasonmolenda jasonmolenda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, LGTM.

@bulbazord bulbazord merged commit 384d69f into llvm:main Aug 27, 2024
9 checks passed
@bulbazord bulbazord deleted the cleanup-dyld-memory branch August 27, 2024 16:59
JDevlieghere pushed a commit to swiftlang/llvm-project that referenced this pull request Jan 24, 2025
…m#106157)

Without calling `dyld_process_dispose`, LLDB will leak the memory
associated with the `dyld_process_t`.

rdar://134738265
(cherry picked from commit 384d69f)
adrian-prantl added a commit to swiftlang/llvm-project that referenced this pull request Jan 24, 2025
…384d69fcbbd0

[🍒 swift/release/6.1] [lldb] Cleanup dyld_process_t after constructing SharedCacheInfo (llvm#106157)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants