Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
CORTX-33743: Analyze and fix memory leaks (#2088)
Browse files Browse the repository at this point in the history
Problem statement:
Valgrind reported few leaks in the code, where strdup was used for allocating memory to the duplicate string.

Fix Description:
Analyzed the code statically and freed up the variables allocated memory dynamically during the execution.
Attaching the valrind report with the code changes, where no leak is found wrt the leaks described of the JIRA ticket.

Signed-off-by: Swapnil Chaudhary <swapnil.chaudhary@seagate.com>
  • Loading branch information
swapnil-seagate authored Aug 31, 2022
1 parent c3b78e4 commit 9b5d685
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion ha/entrypoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,12 @@ static struct m0_rpc_item_ops ha_entrypoint_client_item_ops = {
static void ha_entrypoint_client_fop_release(struct m0_ref *ref)
{
struct m0_fop *fop;

struct m0_ha_entrypoint_req_fop *req_fop_data;
M0_ENTRY();
M0_PRE(ref != NULL);
fop = container_of(ref, struct m0_fop, f_ref);
req_fop_data = (struct m0_ha_entrypoint_req_fop*)fop->f_data.fd_data;
m0_buf_free(&req_fop_data->erf_git_rev_id);
fop->f_data.fd_data = NULL;
m0_fop_fini(fop);
M0_SET0(fop);
Expand Down
5 changes: 3 additions & 2 deletions motr/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ static void cs_reqh_ctx_fini(struct m0_reqh_context *rctx)
m0_free(rctx->rc_services[i]);
m0_free(rctx->rc_services);
m0_free(rctx->rc_service_fids);
m0_free((char*)rctx->rc_addb_stlocation);
rctx->rc_stob.s_sfile.sf_is_initialised = false;
rctx->rc_stob.s_ad_disks_init = false;
}
Expand Down Expand Up @@ -2291,8 +2292,8 @@ static int _args_parse(struct m0_motr *cctx, int argc, char **argv)
LAMBDA(void, (const char *s)
{
char tmp_buf[512];
sprintf(tmp_buf, "%s-%d", s, (int)m0_pid());
rctx->rc_addb_stlocation = strdup(tmp_buf);
snprintf(tmp_buf, sizeof(tmp_buf), "%s-%d", s, (int)m0_pid());
rctx->rc_addb_stlocation = m0_strdup(tmp_buf);
})),
M0_STRINGARG('d', "Device configuration file",
LAMBDA(void, (const char *s)
Expand Down

0 comments on commit 9b5d685

Please sign in to comment.