Skip to content

Commit

Permalink
fixed race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Sep 10, 2014
1 parent 9e759a5 commit 5abd402
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Garlic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ namespace garlic
SessionDecryption * decryption = new SessionDecryption;
decryption->SetKey (key);
decryption->SetTagCount (1);
std::unique_lock<std::mutex> l(m_SessionsTagsMutex);
m_SessionTags[SessionTag(tag)] = decryption;
}

Expand Down Expand Up @@ -343,6 +344,7 @@ namespace garlic
it->second->UseTag ();
HandleAESBlock (buf + 32, length - 32, it->second, msg->from);
if (!it->second->GetTagCount ()) delete it->second; // all tags were used
std::unique_lock<std::mutex> l(m_SessionsTagsMutex);
m_SessionTags.erase (it); // tag might be used only once
}
else
Expand Down Expand Up @@ -377,6 +379,7 @@ namespace garlic
if (tagCount > 0)
{
decryption->AddTagCount (tagCount);
std::unique_lock<std::mutex> l(m_SessionsTagsMutex);
for (int i = 0; i < tagCount; i++)
m_SessionTags[SessionTag(buf + i*32)] = decryption;
}
Expand Down
1 change: 1 addition & 0 deletions Garlic.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ namespace garlic
std::map<uint32_t, GarlicRoutingSession *> m_CreatedSessions; // msgID -> session
// incoming session
// multiple tags refer to one decyption
std::mutex m_SessionsTagsMutex;
std::map<SessionTag, SessionDecryption *> m_SessionTags; // tag -> decryption
};

Expand Down

0 comments on commit 5abd402

Please sign in to comment.