Skip to content

Commit

Permalink
review: Resolve leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Smjert committed Nov 22, 2023
1 parent 8056745 commit ecd100a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions osquery/tables/utility/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <osquery/filesystem/fileops.h>
#include <osquery/filesystem/filesystem.h>
#include <osquery/logger/logger.h>
#include <osquery/utils/scope_guard.h>
#include <osquery/worker/ipc/platform_table_container_ipc.h>
#include <osquery/worker/logging/glog/glog_logger.h>

Expand Down Expand Up @@ -74,6 +75,9 @@ boost::optional<LnkData> parseLnkData(const fs::path& link) {
return boost::none;
}

auto shell_link_release =
scope_guard::create([shell_link]() { shell_link->Release(); });

IPersistFile* file;
hres = shell_link->QueryInterface(IID_IPersistFile,
reinterpret_cast<LPVOID*>(&file));
Expand All @@ -84,6 +88,8 @@ boost::optional<LnkData> parseLnkData(const fs::path& link) {
return boost::none;
}

auto file_link_release = scope_guard::create([file]() { file->Release(); });

hres = file->Load(link.c_str(), STGM_READ);

if (FAILED(hres)) {
Expand Down

0 comments on commit ecd100a

Please sign in to comment.