Skip to content

[clang][unittests] Fix a leak in SearchPathTest #139335

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

Conversation

ian-twilightcoder
Copy link
Contributor

No description provided.

@llvmbot llvmbot added the clang Clang issues not falling into any other category label May 9, 2025
@llvmbot
Copy link
Member

llvmbot commented May 9, 2025

@llvm/pr-subscribers-clang

Author: Ian Anderson (ian-twilightcoder)

Changes

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

1 Files Affected:

  • (modified) clang/unittests/Frontend/SearchPathTest.cpp (+3-3)
diff --git a/clang/unittests/Frontend/SearchPathTest.cpp b/clang/unittests/Frontend/SearchPathTest.cpp
index 5d382a4ee20a8..2ebe74d47eb02 100644
--- a/clang/unittests/Frontend/SearchPathTest.cpp
+++ b/clang/unittests/Frontend/SearchPathTest.cpp
@@ -51,6 +51,7 @@ class SearchPathTest : public ::testing::Test {
   FileManager FileMgr;
   SourceManager SourceMgr;
   std::unique_ptr<CompilerInvocation> Invocation;
+  IntrusiveRefCntPtr<TargetInfo> Target;
 
   void addDirectories(ArrayRef<StringRef> Dirs) {
     for (StringRef Dir : Dirs) {
@@ -65,10 +66,9 @@ class SearchPathTest : public ::testing::Test {
     CompilerInvocation::CreateFromArgs(*Invocation, Args, Diags);
     HeaderSearchOptions HSOpts = Invocation->getHeaderSearchOpts();
     LangOptions LangOpts = Invocation->getLangOpts();
-    TargetInfo *Target =
-        TargetInfo::CreateTargetInfo(Diags, Invocation->getTargetOpts());
+    Target = TargetInfo::CreateTargetInfo(Diags, Invocation->getTargetOpts());
     auto HeaderInfo = std::make_unique<HeaderSearch>(HSOpts, SourceMgr, Diags,
-                                                     LangOpts, Target);
+                                                     LangOpts, Target.get());
     ApplyHeaderSearchOptions(*HeaderInfo, HSOpts, LangOpts,
                              Target->getTriple());
     return HeaderInfo;

@vitalybuka
Copy link
Collaborator

I checked on the bot, this fixes the leak!
Thank you!

@vitalybuka vitalybuka merged commit ce9a898 into llvm:main May 9, 2025
8 of 11 checks passed
@ian-twilightcoder ian-twilightcoder deleted the darwin-framework-search-paths branch May 13, 2025 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants