Skip to content

[NFC]Fix memory leak in HeaderSearchTest #95927

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
Jun 18, 2024
Merged

[NFC]Fix memory leak in HeaderSearchTest #95927

merged 1 commit into from
Jun 18, 2024

Conversation

dklimkin
Copy link
Member

AddressSanitizer: 56 byte(s) leaked in 1 allocation(s). (clang/unittests:lex_tests)

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jun 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 18, 2024

@llvm/pr-subscribers-clang

Author: Danial Klimkin (dklimkin)

Changes

AddressSanitizer: 56 byte(s) leaked in 1 allocation(s). (clang/unittests:lex_tests)


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

1 Files Affected:

  • (modified) clang/unittests/Lex/HeaderSearchTest.cpp (+4-2)
diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp
index 38ce3812c204f..b0375d5985f2e 100644
--- a/clang/unittests/Lex/HeaderSearchTest.cpp
+++ b/clang/unittests/Lex/HeaderSearchTest.cpp
@@ -19,6 +19,8 @@
 #include "clang/Serialization/InMemoryModuleCache.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "gtest/gtest.h"
+#include <memory>
+#include <string>
 
 namespace clang {
 namespace {
@@ -350,8 +352,8 @@ TEST_F(HeaderSearchTest, HeaderFileInfoMerge) {
     std::string TextualPath = "/textual.h";
   };
 
-  auto ExternalSource = new MockExternalHeaderFileInfoSource();
-  Search.SetExternalSource(ExternalSource);
+  auto ExternalSource = std::make_unique<MockExternalHeaderFileInfoSource>();
+  Search.SetExternalSource(ExternalSource.get());
 
   // Everything should start out external.
   auto ModularFE = AddHeader(ExternalSource->ModularPath);

@dklimkin dklimkin changed the title Fix memory leak in HeaderSearchTest [NFC]Fix memory leak in HeaderSearchTest Jun 18, 2024
@dklimkin dklimkin merged commit f1eae81 into llvm:main Jun 18, 2024
6 of 8 checks passed
@AaronBallman
Copy link
Collaborator

Thank you for the fix! FWIW, I don't think this is NFC as it is changing test behavior (fixing a memory leak); please be sure to get a proper code review for functional changes. The changes are reasonable enough, but one question I have is: why not stack allocate the object rather than heap allocate it?

AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
AddressSanitizer: 56 byte(s) leaked in 1 allocation(s).
(clang/unittests:lex_tests)
@dklimkin
Copy link
Member Author

Hi AaronBallman, I think I opted to have a minimal change, it was on heap and I kept it this way. Seems not important for a test only code.

As per NFC, thank you for the note. I considered it NFC as the prod code behavior didn't change. I'll keep in mind any behavior change counts.

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.

3 participants