Skip to content

Commit

Permalink
issue-1902: fixing use-after-free after #1818
Browse files Browse the repository at this point in the history
  • Loading branch information
qkrorlqr committed Sep 1, 2024
1 parent 3af0964 commit 96335c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TNodeToSessionStat::EKind TNodeToSessionStat::AddWrite(
}

void TNodeToSessionStat::Clean(
const TStat::iterator& nodeStatIterator,
TStat::iterator& nodeStatIterator,
const TString& sessionId)
{
auto& nodeStat = nodeStatIterator->second;
Expand All @@ -40,14 +40,15 @@ void TNodeToSessionStat::Clean(

if (nodeStat.WriteSessions.empty() && nodeStat.ReadSessions.empty()) {
Stat.erase(nodeStatIterator);
nodeStatIterator = Stat.end();
}
}

TNodeToSessionStat::EKind TNodeToSessionStat::RemoveRead(
ui64 nodeId,
const TString& sessionId)
{
const auto& nodeStatIterator = Stat.find(nodeId);
auto nodeStatIterator = Stat.find(nodeId);
if (nodeStatIterator != Stat.end()) {
--nodeStatIterator->second.ReadSessions[sessionId];
Clean(nodeStatIterator, sessionId);
Expand All @@ -59,7 +60,7 @@ TNodeToSessionStat::EKind TNodeToSessionStat::RemoveWrite(
ui64 nodeId,
const TString& sessionId)
{
const auto& nodeStatIterator = Stat.find(nodeId);
auto nodeStatIterator = Stat.find(nodeId);
if (nodeStatIterator != Stat.end()) {
--nodeStatIterator->second.WriteSessions[sessionId];
Clean(nodeStatIterator, sessionId);
Expand Down
8 changes: 4 additions & 4 deletions cloud/filestore/libs/storage/tablet/model/node_session_stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ class TNodeToSessionStat
using TStat = THashMap<ui64, TSessionStat>;
TStat Stat;

void Clean(
const TStat::iterator& nodeStatIterator,
const TString& sessionId);

public:
enum class EKind
{
Expand All @@ -38,6 +34,10 @@ class TNodeToSessionStat
private:
[[nodiscard]] EKind GetKind(
const TStat::const_iterator& nodeStatIterator) const;

void Clean(
TStat::iterator& nodeStatIterator,
const TString& sessionId);
};

} // namespace NCloud::NFileStore::NStorage

0 comments on commit 96335c8

Please sign in to comment.