From e69b24f4413f15bc4095376b6d37b07ba4da3332 Mon Sep 17 00:00:00 2001 From: Cedric Koch-Hofer Date: Tue, 28 Apr 2026 09:51:19 +0000 Subject: [PATCH 1/4] DAOS-18304 ddb: fix ddb_run_feature dc_poh/dc_write_mode reset guard When the pool was already open before ddb_run_feature() was called (i.e. the 'close' flag is false), resetting dc_poh to DAOS_HDL_INVAL and dc_write_mode to false unconditionally corrupted the caller's pool state. Guard these resets inside the 'if (close)' block so they only execute when this function itself opened the pool. Signed-off-by: Cedric Koch-Hofer --- src/utils/ddb/ddb_commands.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/ddb/ddb_commands.c b/src/utils/ddb/ddb_commands.c index 63af1e1f522..fc5477f6e94 100644 --- a/src/utils/ddb/ddb_commands.c +++ b/src/utils/ddb/ddb_commands.c @@ -1148,10 +1148,11 @@ ddb_run_feature(struct ddb_ctx *ctx, struct feature_options *opt) ddb_printf(ctx, "Incompat Flags: %lu\n", new_incompat_flags); } out: - if (close) + if (close) { rc = dv_pool_close(ctx->dc_poh); - ctx->dc_poh = DAOS_HDL_INVAL; - ctx->dc_write_mode = false; + ctx->dc_poh = DAOS_HDL_INVAL; + ctx->dc_write_mode = false; + } return rc; } From 343957a64862980221a6c6ad5aa7a5619c17fee5 Mon Sep 17 00:00:00 2001 From: Cedric Koch-Hofer Date: Tue, 28 Apr 2026 09:51:52 +0000 Subject: [PATCH 2/4] DAOS-18304 ddb: fix memory leaks and defer ordering in Go wrappers - Feature(): C.CString(enable) and C.CString(disable) were passed directly to ddb_feature_string2flags() without ever being freed. Assign them to named variables so defer freeString() can release them. - DtxStat(): options.details was set before defer freeString(options.path), inverting the defer execution order. Move the defer immediately after the CString allocation. Signed-off-by: Cedric Koch-Hofer --- src/control/cmd/ddb/commands_wrapper.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/control/cmd/ddb/commands_wrapper.go b/src/control/cmd/ddb/commands_wrapper.go index d9751dbd8e5..eaa26832c09 100644 --- a/src/control/cmd/ddb/commands_wrapper.go +++ b/src/control/cmd/ddb/commands_wrapper.go @@ -247,14 +247,18 @@ func ddbFeature(ctx *DdbContext, path, enable, disable string, show bool) error defer freeString(options.path) options.db_path = ctx.ctx.dc_db_path if enable != "" { - err := daosError(C.ddb_feature_string2flags(&ctx.ctx, C.CString(enable), + cEnable := C.CString(enable) + defer freeString(cEnable) + err := daosError(C.ddb_feature_string2flags(&ctx.ctx, cEnable, &options.set_compat_flags, &options.set_incompat_flags)) if err != nil { return err } } if disable != "" { - err := daosError(C.ddb_feature_string2flags(&ctx.ctx, C.CString(disable), + cDisable := C.CString(disable) + defer freeString(cDisable) + err := daosError(C.ddb_feature_string2flags(&ctx.ctx, cDisable, &options.clear_compat_flags, &options.clear_incompat_flags)) if err != nil { return err @@ -312,8 +316,8 @@ func ddbDtxStat(ctx *DdbContext, path string, details bool) error { /* Set up the options */ options := C.struct_dtx_stat_options{} options.path = C.CString(path) - options.details = C.bool(details) defer freeString(options.path) + options.details = C.bool(details) /* Run the c code command */ return daosError(C.ddb_run_dtx_stat(&ctx.ctx, &options)) } From 47472c9fc25ae15c7e2a8d849bde00bdc0b6f280 Mon Sep 17 00:00:00 2001 From: Cedric Koch-Hofer Date: Tue, 28 Apr 2026 09:52:20 +0000 Subject: [PATCH 3/4] DAOS-18304 ddb: fix test bugs in read_only_vs_write_mode_test - helper_stat_open_modify_close_stat() overwrote tctx->dvt_poh with the temporary pool handle opened for the test and never restored it, leaving the suite-level pool handle invalid for all subsequent tests. Save and restore the original handle around the open/close sequence. - read_only_vs_write_mode_test() passed fs[FILE_STATE_PRE].digest as both arguments to assert_memory_equal(), comparing the pre-digest against itself and making the read-only assertion a no-op. Use fs[FILE_STATE_POST].digest as the second argument. Signed-off-by: Cedric Koch-Hofer --- src/utils/ddb/tests/ddb_vos_tests.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils/ddb/tests/ddb_vos_tests.c b/src/utils/ddb/tests/ddb_vos_tests.c index 6297f55395f..933d497ed27 100644 --- a/src/utils/ddb/tests/ddb_vos_tests.c +++ b/src/utils/ddb/tests/ddb_vos_tests.c @@ -1176,8 +1176,9 @@ static void helper_stat_open_modify_close_stat(struct dt_vos_pool_ctx *tctx, struct file_state fs[2], bool write_mode) { - const char *path = tctx->dvt_pmem_file; + const char *path = tctx->dvt_pmem_file; struct vos_file_parts path_parts = {0}; + daos_handle_t saved_poh = tctx->dvt_poh; assert_int_equal(stat(path, &fs[FILE_STATE_PRE].stat), 0); sha256sum(path, fs[FILE_STATE_PRE].digest); @@ -1186,6 +1187,7 @@ helper_stat_open_modify_close_stat(struct dt_vos_pool_ctx *tctx, struct file_sta assert_success(dv_pool_open(path, &path_parts, &tctx->dvt_poh, 0, write_mode)); update_value_to_modify_tests((void **)&tctx); assert_success(dv_pool_close(tctx->dvt_poh)); + tctx->dvt_poh = saved_poh; assert_int_equal(stat(path, &fs[FILE_STATE_POST].stat), 0); sha256sum(path, fs[FILE_STATE_POST].digest); @@ -1200,7 +1202,7 @@ read_only_vs_write_mode_test(void **state) /** In read‑only mode, the pool contents remain unchanged, and its mtime stays the same. */ helper_stat_open_modify_close_stat(tctx, fs, false /** read-only */); assert_int_equal(fs[FILE_STATE_PRE].stat.st_mtime, fs[FILE_STATE_POST].stat.st_mtime); - assert_memory_equal(fs[FILE_STATE_PRE].digest, fs[FILE_STATE_PRE].digest, + assert_memory_equal(fs[FILE_STATE_PRE].digest, fs[FILE_STATE_POST].digest, SHA256_DIGEST_LEN); /** In write mode, the pool contents will change and its mtime will increase. */ From 7d47113c406ce923a515426ba5bc7259282d5827 Mon Sep 17 00:00:00 2001 From: Cedric Koch-Hofer Date: Tue, 28 Apr 2026 09:52:20 +0000 Subject: [PATCH 4/4] DAOS-18304 ddb: fix clang format Fix clang format issue detected by CI. Signed-off-by: Cedric Koch-Hofer --- src/utils/ddb/tests/ddb_vos_tests.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/ddb/tests/ddb_vos_tests.c b/src/utils/ddb/tests/ddb_vos_tests.c index 933d497ed27..74f76839b7d 100644 --- a/src/utils/ddb/tests/ddb_vos_tests.c +++ b/src/utils/ddb/tests/ddb_vos_tests.c @@ -1176,9 +1176,9 @@ static void helper_stat_open_modify_close_stat(struct dt_vos_pool_ctx *tctx, struct file_state fs[2], bool write_mode) { - const char *path = tctx->dvt_pmem_file; + const char *path = tctx->dvt_pmem_file; struct vos_file_parts path_parts = {0}; - daos_handle_t saved_poh = tctx->dvt_poh; + daos_handle_t saved_poh = tctx->dvt_poh; assert_int_equal(stat(path, &fs[FILE_STATE_PRE].stat), 0); sha256sum(path, fs[FILE_STATE_PRE].digest);