From: Xiao Guodong Date: Thu, 25 Jul 2019 08:36:05 +0000 (+0800) Subject: cephfs: avoid map been inserted by mistake X-Git-Tag: v13.2.7~99^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f51c4a83f33e544cd4df2bfba03842eddfdee2a4;p=ceph.git 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 (cherry picked from commit 1959fee90a3f4eb351b2975a56b386a0a516239d) --- diff --git a/src/mds/SnapRealm.h b/src/mds/SnapRealm.h index d904852167b9..37065eb1d00b 100644 --- a/src/mds/SnapRealm.h +++ b/src/mds/SnapRealm.h @@ -148,9 +148,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); } } };