This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix leak in LoadFromCommandLineWorkingDirectory unit test
ClosedPublic

Authored by hamishknight on Jun 30 2023, 1:47 PM.

Details

Summary

Change ASTUnit::LoadFromCommandLine to return a std::unique_ptr instead of a +1 pointer, fixing a leak in the unit test LoadFromCommandLineWorkingDirectory.

Diff Detail

Event Timeline

hamishknight created this revision.Jun 30 2023, 1:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2023, 1:47 PM
hamishknight requested review of this revision.Jun 30 2023, 1:47 PM
bnbarham accepted this revision.Jun 30 2023, 1:52 PM
This revision is now accepted and ready to land.Jun 30 2023, 1:52 PM
benlangmuir accepted this revision.Jun 30 2023, 2:12 PM

Gotta love return AST.release() being passed directly back into std::unique_ptr<ASTUnit>(...). Thanks for fixing!

clang/tools/libclang/CIndex.cpp
3965

Nit: the style guidance for auto in llvm is "type is already obvious from the context". Since I don't think that's obvious here (in particular, this code would have compiled with the raw pointer return type), and the type name will not be verbose, I think we should keep std::unique_ptr<ASTUnit>. Same for the other calls below.

Updated to use explicit std::unique_ptr<ASTUnit>

hamishknight marked an inline comment as done.Jun 30 2023, 2:19 PM
hamishknight added inline comments.
clang/tools/libclang/CIndex.cpp
3965

Fair enough, updated

hamishknight marked an inline comment as done.Jun 30 2023, 2:20 PM
This revision was landed with ongoing or failed builds.Jun 30 2023, 4:03 PM
This revision was automatically updated to reflect the committed changes.