]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs: avoid map been inserted by mistake 29878/head
authorXiao Guodong <xiaogd@inspur.com>
Thu, 25 Jul 2019 08:36:05 +0000 (16:36 +0800)
committerPrashant D <pdhange@redhat.com>
Mon, 26 Aug 2019 00:37:09 +0000 (20:37 -0400)
if map client_caps has not key client, client_caps[client] will insert key client with null value into the map.

Fixes: https://tracker.ceph.com/issues/40939
Signed-off-by: XiaoGuoDong2019 <xiaogd@inspur.com>
(cherry picked from commit 1959fee90a3f4eb351b2975a56b386a0a516239d)

src/mds/SnapRealm.h

index 62d6cba952a401bd7870c020e1f2c1affe10e1f0..17849e4f926f667c8097321769a5cc2238f6e670 100644 (file)
@@ -147,9 +147,10 @@ public:
   }
   void remove_cap(client_t client, Capability *cap) {
     cap->item_snaprealm_caps.remove_myself();
-    if (client_caps[client]->empty()) {
-      delete client_caps[client];
-      client_caps.erase(client);
+    auto found = client_caps.find(client);
+    if (found != client_caps.end() && found->second->empty()) {
+      delete found->second;
+      client_caps.erase(found);
     }
   }
 };