diff options
author | Kun Yi <kunyi731@gmail.com> | 2019-11-22 14:59:40 -0800 |
---|---|---|
committer | Kun Yi <kunyi731@gmail.com> | 2019-11-25 10:06:06 -0800 |
commit | cd833aa11075ac1041531270060e1fb3ba8aa5ac (patch) | |
tree | f416d4c5fbf8e0d5cdc5993561ab0c253c9c7598 | |
parent | fea1d8115bace4bedae2523a9d9389a990adb09f (diff) | |
download | phosphor-ipmi-blobs-cd833aa11075ac1041531270060e1fb3ba8aa5ac.tar.gz phosphor-ipmi-blobs-cd833aa11075ac1041531270060e1fb3ba8aa5ac.zip |
Fix openFiles refcount
The old code deletes session from the session map before doing a lookup
of the path. Fix the order and add a unit test to catch the error case.
(The unit test would fail without this fix).
Signed-off-by: Kun Yi <kunyi731@gmail.com>
Change-Id: If043d6aad7bbaafa19ae3b63a6d9cc7a836d25b5
-rw-r--r-- | manager.cpp | 3 | ||||
-rw-r--r-- | test/manager_delete_unittest.cpp | 24 |
2 files changed, 26 insertions, 1 deletions
diff --git a/manager.cpp b/manager.cpp index 0eec6f2..870bf60 100644 --- a/manager.cpp +++ b/manager.cpp @@ -27,7 +27,6 @@ namespace blobs void BlobManager::eraseSession(GenericBlobInterface* handler, uint16_t session) { - sessions.erase(session); /* Ok for openSessions[handler] to be an empty set */ openSessions[handler].erase(session); @@ -37,6 +36,8 @@ void BlobManager::eraseSession(GenericBlobInterface* handler, uint16_t session) { openFiles.erase(path); } + /* Cannot erase before getPath() is called */ + sessions.erase(session); } void BlobManager::cleanUpStaleSessions(GenericBlobInterface* handler) diff --git a/test/manager_delete_unittest.cpp b/test/manager_delete_unittest.cpp index 9ad3afd..0a59aa7 100644 --- a/test/manager_delete_unittest.cpp +++ b/test/manager_delete_unittest.cpp @@ -84,4 +84,28 @@ TEST(ManagerDeleteTest, FileIsNotOpenAndHandlerSucceeds) // Try to delete the file. EXPECT_TRUE(mgr.deleteBlob(path)); } + +TEST(ManagerDeleteTest, DeleteWorksAfterOpenClose) +{ + // The Blob manager is able to decrement the ref count and delete. + + BlobManager mgr; + std::unique_ptr<BlobMock> m1 = std::make_unique<BlobMock>(); + auto m1ptr = m1.get(); + EXPECT_TRUE(mgr.registerHandler(std::move(m1))); + + uint16_t flags = OpenFlags::read, sess; + std::string path = "/asdf/asdf"; + + EXPECT_CALL(*m1ptr, canHandleBlob(path)).WillRepeatedly(Return(true)); + EXPECT_CALL(*m1ptr, open(_, flags, path)).WillOnce(Return(true)); + EXPECT_CALL(*m1ptr, close(_)).WillOnce(Return(true)); + EXPECT_CALL(*m1ptr, deleteBlob(path)).WillOnce(Return(true)); + + EXPECT_TRUE(mgr.open(flags, path, &sess)); + EXPECT_TRUE(mgr.close(sess)); + + // Try to delete the file. + EXPECT_TRUE(mgr.deleteBlob(path)); +} } // namespace blobs |