Skip to content

Commit 3b27b86

Browse files
committed
fix: fix cross dll memory release
1 parent 0d4cd3f commit 3b27b86

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

src/pl/dependency/DependencyWalker.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,22 @@ static std::unique_ptr<DependencyIssueItem> createDiagnosticMessage( // NOLINT(m
7676
}
7777

7878
static void printDependencyError( // NOLINT(misc-no-recursion)
79-
std::unique_ptr<DependencyIssueItem> const& item,
80-
std::ostream& stream,
81-
size_t depth = 0
79+
DependencyIssueItem const& item,
80+
std::ostream& stream,
81+
size_t depth = 0
8282
) {
8383
std::string indent(depth * 3 + 3, ' ');
84-
if (item->mContainsError) {
85-
stream << indent << fmt::format("module: {}", pl::utils::u8str2str(item->mPath.u8string())) << std::endl;
86-
if (!item->mMissingModule.empty()) {
84+
if (item.mContainsError) {
85+
stream << indent << fmt::format("module: {}", pl::utils::u8str2str(item.mPath.u8string())) << std::endl;
86+
if (!item.mMissingModule.empty()) {
8787
stream << indent << "missing module:" << std::endl;
88-
for (const auto& missingModule : item->mMissingModule) {
88+
for (const auto& missingModule : item.mMissingModule) {
8989
stream << indent << "|- " << missingModule << std::endl;
9090
}
9191
}
92-
if (!item->mMissingProcedure.empty()) {
92+
if (!item.mMissingProcedure.empty()) {
9393
stream << indent << "missing procedure:" << std::endl;
94-
for (const auto& [module, missingProcedure] : item->mMissingProcedure) {
94+
for (const auto& [module, missingProcedure] : item.mMissingProcedure) {
9595
stream << indent << "|- " << module << std::endl;
9696
for (const auto& procedure : missingProcedure) {
9797
stream << indent << "|---- " << procedure << std::endl;
@@ -101,24 +101,30 @@ static void printDependencyError( // NOLINT(misc-no-recursion)
101101
}
102102
}
103103
}
104-
if (!item->mDependencies.empty()) {
105-
for (const auto& [module, subItem] : item->mDependencies) {
106-
printDependencyError(subItem, stream, depth + 1);
104+
if (!item.mDependencies.empty()) {
105+
for (const auto& [module, subItem] : item.mDependencies) {
106+
printDependencyError(*subItem, stream, depth + 1);
107107
}
108108
}
109109
}
110110
}
111111

112-
std::unique_ptr<DependencyIssueItem> pl::dependency_walker::pl_diagnostic_dependency(fs::path const& path) {
112+
static void deleteDependencyIssueItem(DependencyIssueItem* item) { delete item; }
113+
114+
std::unique_ptr<DependencyIssueItem, void (*)(DependencyIssueItem*)>
115+
pl::dependency_walker::pl_diagnostic_dependency(fs::path const& path) {
113116
auto libSearcher = LibrarySearcher::getInstance();
114117
auto systemRoot = pl::utils::getSystemRoot().u8string();
115118
auto provider = std::make_unique<PortableExecutableProvider>(libSearcher, systemRoot, path);
116-
return createDiagnosticMessage(path, std::move(provider), libSearcher, systemRoot);
119+
return {
120+
createDiagnosticMessage(path, std::move(provider), libSearcher, systemRoot).release(),
121+
deleteDependencyIssueItem
122+
};
117123
}
118124

119125
std::string pl::dependency_walker::pl_diagnostic_dependency_string(fs::path const& path) {
120126
auto result = pl_diagnostic_dependency(path);
121127
std::stringstream stream;
122-
printDependencyError(result, stream);
128+
printDependencyError(*result, stream);
123129
return stream.str();
124130
}

src/pl/dependency/DependencyWalker.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ struct DependencyIssueItem {
2424
* @param path [in] The path of the library to diagnose.
2525
* @return result The result of the diagnosis.
2626
*/
27-
PLAPI std::unique_ptr<DependencyIssueItem> pl_diagnostic_dependency(std::filesystem::path const& path);
27+
PLAPI std::unique_ptr<DependencyIssueItem, void (*)(DependencyIssueItem*)>
28+
pl_diagnostic_dependency(std::filesystem::path const& path);
2829

2930
/**
3031
* @brief Diagnose the dependency of a library.

0 commit comments

Comments
 (0)