Skip to content
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

Memory leak fix for 1.28.1 #50

Merged
merged 2 commits into from
Sep 22, 2024
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
4 changes: 4 additions & 0 deletions source/P4VFS.Console/P4VFS.Notes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Microsoft P4VFS Release Notes

Version [1.28.1.0]
* Fixing possible memory leak during sync operation while accumulating logging
elements for statistics

Version [1.28.0.0]
* Addition of 'dehydrate' command as synonym for 'resident -v', for changing existing
files from #have to zero-byte placeholder files. Unit tests included.
Expand Down
8 changes: 8 additions & 0 deletions source/P4VFS.Core/Include/LogDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,23 @@ namespace FileCore {

struct LogDeviceMemory : LogDevice
{
LogDeviceMemory();

virtual void Write(const LogElement& element) override;
const List<LogElement>& GetElements() const;

private:
List<LogElement> m_Elements;
AutoHandle m_ElementsMutex;
};

struct LogDeviceAggregate : LogDevice
{
virtual void Write(const LogElement& element) override;
virtual bool IsFaulted() override;
void AddDevice(LogDevice* device);

private:
Array<LogDevice*> m_Devices;
};

Expand All @@ -197,6 +204,7 @@ namespace FileCore {
virtual void Write(const LogElement& element) override;
virtual bool IsFaulted() override;

private:
LogDevice* m_InnerDevice;
LogChannel::Enum m_Level;
};
Expand Down
14 changes: 7 additions & 7 deletions source/P4VFS.Core/Source/DepotOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ DepotOperations::SyncVirtual(

if (depotClient->Log() != nullptr)
{
aggregateLog.m_Devices.push_back(depotClient->Log());
aggregateLog.m_Devices.push_back(&memoryLog);
aggregateLog.AddDevice(depotClient->Log());
aggregateLog.AddDevice(&memoryLog);
log = &aggregateLog;
}

Expand Down Expand Up @@ -479,7 +479,7 @@ DepotOperations::ApplyVirtualModification(
// Flush buffered log all at once
if (log == &memoryLog && parentLog != nullptr)
{
for (const LogElement& element : memoryLog.m_Elements)
for (const LogElement& element : memoryLog.GetElements())
{
parentLog->Write(element.m_Channel, element.m_Text);
}
Expand Down Expand Up @@ -749,8 +749,8 @@ DepotOperations::SyncRegular(

if (depotClient->Log() != nullptr)
{
aggregateLog.m_Devices.push_back(depotClient->Log());
aggregateLog.m_Devices.push_back(&memoryLog);
aggregateLog.AddDevice(depotClient->Log());
aggregateLog.AddDevice(&memoryLog);
log = &aggregateLog;
}

Expand Down Expand Up @@ -1430,10 +1430,10 @@ DepotOperations::LogWarningErrorSummary(
return e.m_Channel == LogChannel::Warning || e.m_Channel == LogChannel::Error;
};

if (Algo::Any(memoryLog.m_Elements, std::not_fn(inSummary)))
if (Algo::Any(memoryLog.GetElements(), std::not_fn(inSummary)))
{
bool writeHeader = true;
for (const LogElement& element : memoryLog.m_Elements)
for (const LogElement& element : memoryLog.GetElements())
{
if (inSummary(element))
{
Expand Down
2 changes: 1 addition & 1 deletion source/P4VFS.Core/Source/DepotSyncAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ DepotSyncStatus::Enum DepotSyncStatus::FromLog(const LogDeviceMemory& log)
{
StaticAssert(DepotSyncStatus::Success == 0);
DepotSyncStatus::Enum status = DepotSyncStatus::Success;
for (const LogElement& element : log.m_Elements)
for (const LogElement& element : log.GetElements())
{
status |= FromLogElement(element);
}
Expand Down
16 changes: 16 additions & 0 deletions source/P4VFS.Core/Source/LogDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,22 @@ String LogDeviceFile::ExpandVariables(const String& text) const
return StringInfo::Replace(text.c_str(), VariableUserName, StringInfo::ToLower(GetDesiredUserName().c_str()).c_str(), StringInfo::SearchCase::Insensitive);
}

LogDeviceMemory::LogDeviceMemory() :
m_ElementsMutex(CreateMutex(NULL, FALSE, NULL))
{
}

void LogDeviceMemory::Write(const LogElement& element)
{
AutoMutex elementsScope(m_ElementsMutex);
m_Elements.push_back(element);
}

const List<LogElement>& LogDeviceMemory::GetElements() const
{
return m_Elements;
}

void LogDeviceAggregate::Write(const LogElement& element)
{
for (LogDevice* device : m_Devices)
Expand All @@ -225,6 +236,11 @@ bool LogDeviceAggregate::IsFaulted()
return false;
}

void LogDeviceAggregate::AddDevice(LogDevice* device)
{
m_Devices.push_back(device);
}

LogDeviceFilter::LogDeviceFilter(LogDevice* device, LogChannel::Enum level) :
m_InnerDevice(device),
m_Level(level)
Expand Down