From 1959fee90a3f4eb351b2975a56b386a0a516239d Mon Sep 17 00:00:00 2001 From: Xiao Guodong Date: Thu, 25 Jul 2019 16:36:05 +0800 Subject: [PATCH] cephfs: avoid map been inserted by mistake 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 --- src/mds/SnapRealm.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mds/SnapRealm.h b/src/mds/SnapRealm.h index 62d6cba952a4..17849e4f926f 100644 --- a/src/mds/SnapRealm.h +++ b/src/mds/SnapRealm.h @@ -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); } } }; -- 2.47.3