Skip to content

[ScanDependencies] Fix a memory leak in dependency graph #75254

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/DependencyScan/DependencyScanJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ static void
writeMacroDependencies(llvm::raw_ostream &out,
const swiftscan_macro_dependency_set_t *macro_deps,
unsigned indentLevel, bool trailingComma) {
if (macro_deps->count == 0)
if (!macro_deps)
return;

out.indent(indentLevel * 2);
Expand Down
5 changes: 1 addition & 4 deletions lib/DependencyScan/DependencyScanningTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@ static swiftscan_dependency_graph_t generateHollowDiagnosticOutput(
// Hollow info details
swiftscan_module_details_s *hollowDetails = new swiftscan_module_details_s;
hollowDetails->kind = SWIFTSCAN_DEPENDENCY_INFO_SWIFT_TEXTUAL;
swiftscan_macro_dependency_set_t *hollowMacroSet = new swiftscan_macro_dependency_set_t;
hollowMacroSet->count = 0;
hollowMacroSet->macro_dependencies = nullptr;
hollowDetails->swift_textual_details = {c_string_utils::create_null(),
c_string_utils::create_empty_set(),
c_string_utils::create_null(),
Expand All @@ -232,7 +229,7 @@ static swiftscan_dependency_graph_t generateHollowDiagnosticOutput(
c_string_utils::create_null(),
c_string_utils::create_null(),
c_string_utils::create_null(),
hollowMacroSet};
nullptr};
hollowMainModuleInfo->details = hollowDetails;

// Empty Link Library set
Expand Down
8 changes: 3 additions & 5 deletions lib/DependencyScan/ScanDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,10 @@ static void bridgeDependencyIDs(const ArrayRef<ModuleDependencyID> dependencies,

static swiftscan_macro_dependency_set_t *createMacroDependencySet(
const std::map<std::string, MacroPluginDependency> &macroDeps) {
if (macroDeps.empty())
return nullptr;

swiftscan_macro_dependency_set_t *set = new swiftscan_macro_dependency_set_t;
if (macroDeps.empty()) {
set->count = 0;
set->macro_dependencies = nullptr;
return set;
}
set->count = macroDeps.size();
set->macro_dependencies = new swiftscan_macro_dependency_t[set->count];
unsigned SI = 0;
Expand Down
4 changes: 4 additions & 0 deletions tools/libSwiftScan/libSwiftScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DependencyScanningTool, swiftscan_scanner_t)
//=== Private Cleanup Functions -------------------------------------------===//
void swiftscan_macro_dependency_dispose(
swiftscan_macro_dependency_set_t *macro) {
if (!macro)
return;

for (unsigned i = 0; i < macro->count; ++i) {
swiftscan_string_dispose(macro->macro_dependencies[i]->moduleName);
swiftscan_string_dispose(macro->macro_dependencies[i]->libraryPath);
swiftscan_string_dispose(macro->macro_dependencies[i]->executablePath);
delete macro->macro_dependencies[i];
}
delete[] macro->macro_dependencies;
delete macro;
}

Expand Down