From df22fea97654ae64643faa87f15c4ae76757633b Mon Sep 17 00:00:00 2001 From: Upendra Patwardhan Date: Mon, 8 Aug 2022 03:27:55 -0600 Subject: [PATCH 1/3] Fix leaks for emap_it_get_cb(). Signed-off-by: Upendra Patwardhan --- be/extmap.c | 10 +++++++--- motr/m0d.c | 12 ++++++------ stob/ad.c | 5 +++++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/be/extmap.c b/be/extmap.c index 7691ef7610e..b87aaab6165 100644 --- a/be/extmap.c +++ b/be/extmap.c @@ -1225,9 +1225,9 @@ static int emap_it_open(struct m0_be_emap_cursor *it, int prev_rc) ext->ee_val = rec->er_value; ext->ee_cksum_buf.b_nob = rec->er_cksum_nob; ext->ee_cksum_buf.b_addr = rec->er_cksum_nob ? - (void *)&rec->er_footer : NULL; + (void *)&rec->er_footer : NULL; it->ec_unit_size = rec->er_unit_size; - if (!emap_it_prefix_ok(it)) + if (!emap_it_prefix_ok(it)) rc = -ESRCH; } it->ec_op.bo_u.u_emap.e_rc = rc; @@ -1254,7 +1254,7 @@ static void emap_it_init(struct m0_be_emap_cursor *it, static void be_emap_close(struct m0_be_emap_cursor *it) { if (it->ec_recbuf.b_addr != NULL ) { - m0_buf_free(&it->ec_recbuf); + m0_buf_free(&it->ec_recbuf); } m0_btree_cursor_fini(&it->ec_cursor); @@ -1537,6 +1537,10 @@ be_emap_split(struct m0_be_emap_cursor *it, rc = emap_it_get(it); it->ec_op.bo_u.u_emap.e_rc = rc; + if (it->ec_recbuf.b_addr != NULL) { + m0_buf_free(&it->ec_recbuf); + it->ec_recbuf.b_addr = NULL; + } return M0_RC(rc); } diff --git a/motr/m0d.c b/motr/m0d.c index 47bbb9de2d9..33c4909f8e1 100644 --- a/motr/m0d.c +++ b/motr/m0d.c @@ -123,7 +123,7 @@ M0_INTERNAL int main(int argc, char **argv) int result; int rc; struct m0_motr motr_ctx; - struct rlimit rlim = {10240, 10240}; + // struct rlimit rlim = {10240, 10240}; if (argc > 1 && (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)) { @@ -149,11 +149,11 @@ M0_INTERNAL int main(int argc, char **argv) } } - rc = setrlimit(RLIMIT_NOFILE, &rlim); - if (rc != 0) { - warnx("\n Failed to setrlimit\n"); - goto out; - } + // rc = setrlimit(RLIMIT_NOFILE, &rlim); + // if (rc != 0) { + // warnx("\n Failed to setrlimit\n"); + // goto out; + // } rc = cs_register_signal(); if (rc != 0) { diff --git a/stob/ad.c b/stob/ad.c index 56664fc36b8..352948679d0 100644 --- a/stob/ad.c +++ b/stob/ad.c @@ -555,6 +555,7 @@ static int stob_ad_domain_create(struct m0_stob_type *type, */ rc = m0_balloc_create(dom_key, seg, grp, &cb, &cfg->adg_id.si_fid); + cb->cb_ballroom.ab_ops->bo_fini(&cb->cb_ballroom); rc = rc ?: m0_be_tx_exclusive_open_sync(&tx); M0_ASSERT(adom == NULL); @@ -940,6 +941,10 @@ static int ext_punch(struct m0_stob *stob, struct m0_dtx *tx, })); M0_ASSERT(m0_be_op_is_done(it_op)); + if (it.ec_recbuf.b_addr != NULL) { + m0_buf_free(&it.ec_recbuf); + it.ec_recbuf.b_addr = NULL; + } rc = m0_be_emap_op_rc(&it); m0_be_op_fini(it_op); return M0_RC(rc); From c411dbdfe93d8f510326cb658e3e4015dca0a0fe Mon Sep 17 00:00:00 2001 From: Upendra Patwardhan Date: Mon, 8 Aug 2022 07:09:14 -0600 Subject: [PATCH 2/3] Fix memory leak for root node in balloc-ut. Signed-off-by: Upendra Patwardhan --- balloc/ut/balloc.c | 1 + motr/m0d.c | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/balloc/ut/balloc.c b/balloc/ut/balloc.c index ccd60351025..1fb0fbd4ac6 100644 --- a/balloc/ut/balloc.c +++ b/balloc/ut/balloc.c @@ -118,6 +118,7 @@ int test_balloc_ut_ops(struct m0_be_ut_backend *ut_be, struct m0_be_seg *seg, grp = m0_be_ut_backend_sm_group_lookup(ut_be); rc = m0_balloc_create(0, seg, grp, &motr_balloc, &M0_FID_INIT(0, 1)); M0_UT_ASSERT(rc == 0); + motr_balloc->cb_ballroom.ab_ops->bo_fini(&motr_balloc->cb_ballroom); rc = motr_balloc->cb_ballroom.ab_ops->bo_init (&motr_balloc->cb_ballroom, seg, BALLOC_DEF_BLOCK_SHIFT, diff --git a/motr/m0d.c b/motr/m0d.c index 33c4909f8e1..47bbb9de2d9 100644 --- a/motr/m0d.c +++ b/motr/m0d.c @@ -123,7 +123,7 @@ M0_INTERNAL int main(int argc, char **argv) int result; int rc; struct m0_motr motr_ctx; - // struct rlimit rlim = {10240, 10240}; + struct rlimit rlim = {10240, 10240}; if (argc > 1 && (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)) { @@ -149,11 +149,11 @@ M0_INTERNAL int main(int argc, char **argv) } } - // rc = setrlimit(RLIMIT_NOFILE, &rlim); - // if (rc != 0) { - // warnx("\n Failed to setrlimit\n"); - // goto out; - // } + rc = setrlimit(RLIMIT_NOFILE, &rlim); + if (rc != 0) { + warnx("\n Failed to setrlimit\n"); + goto out; + } rc = cs_register_signal(); if (rc != 0) { From 1094679f7460b2725e58ccac0f6571a429fd7bba Mon Sep 17 00:00:00 2001 From: Upendra Patwardhan Date: Mon, 8 Aug 2022 23:52:47 -0600 Subject: [PATCH 3/3] Remove unwanted code. Signed-off-by: Upendra Patwardhan --- stob/ad.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/stob/ad.c b/stob/ad.c index 352948679d0..a849c5865d4 100644 --- a/stob/ad.c +++ b/stob/ad.c @@ -941,10 +941,6 @@ static int ext_punch(struct m0_stob *stob, struct m0_dtx *tx, })); M0_ASSERT(m0_be_op_is_done(it_op)); - if (it.ec_recbuf.b_addr != NULL) { - m0_buf_free(&it.ec_recbuf); - it.ec_recbuf.b_addr = NULL; - } rc = m0_be_emap_op_rc(&it); m0_be_op_fini(it_op); return M0_RC(rc);