From 2271c69500c0de98b348eb5282c0a5f2c7ae5531 Mon Sep 17 00:00:00 2001 From: jiaqizho Date: Mon, 4 Nov 2019 13:47:46 +0800 Subject: [PATCH] blobfs_bdev_ut : fix memory leak This memory leak bug is very easy to reproduce. You can follow this step to reproduce: 1. clone master spdk , update submoudle 2. ./configure --with-fuse && make -j24 3. valgrind --leak-check=full --error-exitcode=2 test/unit/lib/blobfs/blobfs_bdev.c/blobfs_bdev_ut It show the memory when you run valgrind. This is because the ctx in spdk_blobfs_bdev_mount have not freed when spdk_fs_load(override in blobfs_bdev_ut) passed. So i added a unmount operation after mount operation to fix this problem. Signed-off-by: jiaqizho Change-Id: I770f914123e353dc42d0420c1fb8b34ebdf88f6c Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/473171 Tested-by: SPDK CI Jenkins Reviewed-by: Xiaodong Liu Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris --- .../unit/lib/blobfs/blobfs_bdev.c/blobfs_bdev_ut.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/unit/lib/blobfs/blobfs_bdev.c/blobfs_bdev_ut.c b/test/unit/lib/blobfs/blobfs_bdev.c/blobfs_bdev_ut.c index e0509fe84..64c6f2a3b 100644 --- a/test/unit/lib/blobfs/blobfs_bdev.c/blobfs_bdev_ut.c +++ b/test/unit/lib/blobfs/blobfs_bdev.c/blobfs_bdev_ut.c @@ -45,6 +45,7 @@ bool g_fs_load_fail = false; bool g_fs_unload_fail = false; bool g_bs_bdev_claim_fail = false; bool g_blobfs_fuse_start_fail = false; +struct blobfs_bdev_operation_ctx *g_fs_ctx; const char *g_bdev_name = "ut_bdev"; @@ -88,6 +89,7 @@ spdk_fs_load(struct spdk_bs_dev *dev, fs_send_request_fn send_request_fn, } cb_fn(cb_arg, NULL, rc); + return; } @@ -122,7 +124,7 @@ spdk_fs_init(struct spdk_bs_dev *dev, struct spdk_blobfs_opts *opt, int spdk_bs_bdev_claim(struct spdk_bs_dev *bs_dev, struct spdk_bdev_module *module) { - if (g_bs_bdev_claim_fail == true) { + if (g_bs_bdev_claim_fail) { return -1; } @@ -133,10 +135,13 @@ int spdk_blobfs_fuse_start(const char *bdev_name, const char *mountpoint, struct spdk_filesystem *fs, blobfs_fuse_unmount_cb cb_fn, void *cb_arg, struct spdk_blobfs_fuse **_bfuse) { - if (g_blobfs_fuse_start_fail == true) { + if (g_blobfs_fuse_start_fail) { return -1; } + /* store the ctx for unmount operation */ + g_fs_ctx = cb_arg; + return 0; } @@ -312,6 +317,11 @@ spdk_blobfs_bdev_mount_test(void) /* no fail */ spdk_blobfs_bdev_mount(g_bdev_name, mountpoint, blobfs_bdev_op_complete, NULL); CU_ASSERT(g_fserrno == 0); + CU_ASSERT(g_fs_ctx != NULL); + + /* after mount operation success , we need make sure unmount operation success */ + blobfs_bdev_unmount(g_fs_ctx); + CU_ASSERT(g_fserrno == 0); #endif }