ceph: fix a memory leak on cap_auths in MDS client
authorLuis Henriques (SUSE) <luis.henriques@linux.dev>
Mon, 19 Aug 2024 09:52:17 +0000 (10:52 +0100)
committerIlya Dryomov <idryomov@gmail.com>
Tue, 24 Sep 2024 20:51:33 +0000 (22:51 +0200)
The cap_auths that are allocated during an MDS session opening are never
released, causing a memory leak detected by kmemleak.  Fix this by freeing
the memory allocated when shutting down the MDS client.

Fixes: 1d17de9534cb ("ceph: save cap_auths in MDS client when session is opened")
Signed-off-by: Luis Henriques (SUSE) <luis.henriques@linux.dev>
Reviewed-by: Xiubo Li <xiubli@redhat.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
fs/ceph/mds_client.c

index 9682c6ae38662effaaae382b796e05a00470024d..59eb13aabc81ceb069a1bf63cd9b3b24794be06a 100644 (file)
@@ -6016,6 +6016,18 @@ static void ceph_mdsc_stop(struct ceph_mds_client *mdsc)
                ceph_mdsmap_destroy(mdsc->mdsmap);
        kfree(mdsc->sessions);
        ceph_caps_finalize(mdsc);
+
+       if (mdsc->s_cap_auths) {
+               int i;
+
+               for (i = 0; i < mdsc->s_cap_auths_num; i++) {
+                       kfree(mdsc->s_cap_auths[i].match.gids);
+                       kfree(mdsc->s_cap_auths[i].match.path);
+                       kfree(mdsc->s_cap_auths[i].match.fs_name);
+               }
+               kfree(mdsc->s_cap_auths);
+       }
+
        ceph_pool_perm_destroy(mdsc);
 }