Skip to content

Commit

Permalink
DAOS-6808 misc: Fix cleanuping resources (#5010)
Browse files Browse the repository at this point in the history
Free memory in an error path

Signed-off-by: Dmitry Eremin <dmitry.eremin@intel.com>
  • Loading branch information
Dmitry Eremin authored Mar 17, 2021
1 parent 8937980 commit 3784fcd
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 55 deletions.
23 changes: 8 additions & 15 deletions src/client/array/dc_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1239,18 +1239,18 @@ process_iomap(struct hole_params *params, daos_array_io_t *args)
static int
set_short_read_cb(tse_task_t *task, void *data)
{
struct hole_params *params;
struct hole_params *params = daos_task_get_priv(task);
daos_array_io_t *args;
int i;
int rc = task->dt_result;

D_ASSERT(params != NULL);

if (rc != 0) {
D_ERROR("Failed to get array size "DF_RC"\n", DP_RC(rc));
return rc;
goto out;
}

params = daos_task_get_priv(task);
D_ASSERT(params != NULL);
args = daos_task_get_args(params->ptask);
D_ASSERT(args);

Expand All @@ -1275,11 +1275,9 @@ set_short_read_cb(tse_task_t *task, void *data)

/** memset holes to 0 */
rc = process_iomap(params, args);
if (rc)
return rc;

out:
D_FREE(params);
return 0;
return rc;
}

static int
Expand All @@ -1297,7 +1295,7 @@ check_short_read_cb(tse_task_t *task, void *data)

if (rc != 0) {
D_ERROR("Array Read Failed "DF_RC"\n", DP_RC(rc));
return rc;
D_GOTO(err_params, rc);
}

D_ASSERT(params);
Expand Down Expand Up @@ -1382,12 +1380,7 @@ check_short_read_cb(tse_task_t *task, void *data)
/** memset all holes to 0 */
params->array_size = UINT64_MAX;
rc = process_iomap(params, args);
if (rc)
return rc;

tse_task_complete(task, 0);
D_FREE(params);
return 0;
D_GOTO(err_params, rc);
}

/** Schedule the get size to properly check for short reads */
Expand Down
8 changes: 3 additions & 5 deletions src/client/dfs/dfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2968,16 +2968,14 @@ dfs_release(dfs_obj_t *obj)
break;
default:
D_ERROR("Invalid entry type (not a dir, file, symlink).\n");
rc = EINVAL;
rc = -DER_IO_INVAL;
}

if (rc) {
if (rc)
D_ERROR("daos_obj_close() failed, "DF_RC"\n", DP_RC(rc));
return daos_der2errno(rc);
}

D_FREE(obj);
return 0;
return daos_der2errno(rc);
}

struct dfs_read_params {
Expand Down
7 changes: 3 additions & 4 deletions src/dtx/dtx_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1166,8 +1166,7 @@ dtx_leader_exec_ops_ult(void *arg)
continue;
}

rc = ult_arg->func(dlh, ult_arg->func_arg, i,
dtx_sub_comp_cb);
rc = ult_arg->func(dlh, ult_arg->func_arg, i, dtx_sub_comp_cb);
if (rc) {
sub->dss_result = rc;
break;
Expand All @@ -1184,7 +1183,7 @@ dtx_leader_exec_ops_ult(void *arg)
}
}

D_FREE_PTR(ult_arg);
D_FREE(ult_arg);
}

/**
Expand Down Expand Up @@ -1229,7 +1228,7 @@ dtx_leader_exec_ops(struct dtx_leader_handle *dlh, dtx_sub_func_t func,
DSS_DEEP_STACK_SZ, NULL);
if (rc != 0) {
D_ERROR("ult create failed "DF_RC"\n", DP_RC(rc));
D_FREE_PTR(ult_arg);
D_FREE(ult_arg);
ABT_future_free(&dlh->dlh_future);
D_GOTO(out, rc);
}
Expand Down
4 changes: 2 additions & 2 deletions src/dtx/dtx_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,10 @@ dtx_cf_rec_alloc(struct btr_instance *tins, d_iov_t *key_iov,
if (drr == NULL)
return -DER_NOMEM;

dcrb = (struct dtx_cf_rec_bundle *)val_iov->iov_buf;
dcrb = val_iov->iov_buf;
D_ALLOC_ARRAY(drr->drr_dti, dcrb->dcrb_count);
if (drr->drr_dti == NULL) {
D_FREE_PTR(drr);
D_FREE(drr);
return -DER_NOMEM;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mgmt/srv_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ ds_mgmt_tgt_create_aggregator(crt_rpc_t *source, crt_rpc_t *result,
return -DER_NOMEM;
}

for (i = 0; i < ret_uuids_nr + tc_uuids_nr; i++) {
for (i = 0; i < new_uuids_nr; i++) {
if (i < ret_uuids_nr) {
uuid_copy(new_uuids[i], ret_uuids[i]);
new_ranks[i] = ret_ranks[i];
Expand Down
4 changes: 2 additions & 2 deletions src/object/srv_ec_aggregate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2219,7 +2219,7 @@ ds_obj_ec_aggregate(struct ds_cont_child *cont, daos_epoch_range_t *epr,
if (rc != 0) {
D_ERROR("Fail to start DTX for EC aggregation: "DF_RC"\n",
DP_RC(rc));
goto out;
goto out_close;
}

agg_param.ap_dth = &dth;
Expand Down Expand Up @@ -2249,7 +2249,7 @@ ds_obj_ec_aggregate(struct ds_cont_child *cont, daos_epoch_range_t *epr,

if (rc == 0 && is_current)
cont->sc_ec_agg_eph = epr->epr_hi;

out_close:
dsc_cont_close(ph, agg_param.ap_pool_info.api_cont_hdl);
out:
daos_prop_free(agg_param.ap_prop);
Expand Down
43 changes: 17 additions & 26 deletions src/object/srv_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ obj_rw_complete(crt_rpc_t *rpc, struct obj_io_context *ioc,
bool update = obj_rpc_is_update(rpc);

if (update) {
rc = dtx_sub_init(dth, &orwi->orw_oid,
orwi->orw_dkey_hash);
if (rc == 0)
rc = vos_update_end(ioh, ioc->ioc_map_ver,
&orwi->orw_dkey, status,
&ioc->ioc_io_size, dth);
if (status == 0)
status = dtx_sub_init(dth, &orwi->orw_oid,
orwi->orw_dkey_hash);
rc = vos_update_end(ioh, ioc->ioc_map_ver,
&orwi->orw_dkey, status,
&ioc->ioc_io_size, dth);
} else {
rc = vos_fetch_end(ioh, &ioc->ioc_io_size, status);
}
Expand Down Expand Up @@ -178,14 +178,9 @@ obj_rw_reply(crt_rpc_t *rpc, int status, uint64_t epoch,
d_sg_list_t *sgls = orwo->orw_sgls.ca_arrays;
int j;

for (i = 0; i < orw->orw_nr; i++) {
for (j = 0; j < sgls[i].sg_nr; j++) {
if (sgls[i].sg_iovs[j].iov_buf == NULL)
continue;
for (i = 0; i < orw->orw_nr; i++)
for (j = 0; j < sgls[i].sg_nr; j++)
D_FREE(sgls[i].sg_iovs[j].iov_buf);
sgls[i].sg_iovs[j].iov_buf = NULL;
}
}
}
}
}
Expand Down Expand Up @@ -550,12 +545,12 @@ obj_set_reply_nrs(crt_rpc_t *rpc, daos_handle_t ioh, d_sg_list_t *sgls)
}

/* return sg_nr_out and data size for sgl */
orwo->orw_nrs.ca_count = nrs_count;
D_ALLOC(orwo->orw_nrs.ca_arrays,
nrs_count * (sizeof(uint32_t) + sizeof(daos_size_t)));

if (orwo->orw_nrs.ca_arrays == NULL)
return -DER_NOMEM;

orwo->orw_nrs.ca_count = nrs_count;
orwo->orw_data_sizes.ca_count = nrs_count;
orwo->orw_data_sizes.ca_arrays =
(void *)((char *)orwo->orw_nrs.ca_arrays +
Expand Down Expand Up @@ -977,6 +972,8 @@ obj_fetch_create_maps(crt_rpc_t *rpc, struct bio_desc *biod, daos_iod_t *iods)
/** will be freed in obj_rw_reply */
D_ALLOC_ARRAY(map->iom_recxs, map->iom_nr);
if (map->iom_recxs == NULL) {
for (r = 0; r < i; r++)
D_FREE(maps[r].iom_recxs);
D_FREE(maps);
return -DER_NOMEM;
}
Expand Down Expand Up @@ -1178,10 +1175,8 @@ obj_prep_fetch_sgls(crt_rpc_t *rpc, struct obj_io_context *ioc)
out:
if (rc) {
for (i = 0; i < nr; i++) {
for (i = 0; j < sgls[i].sg_nr; j++) {
for (i = 0; j < sgls[i].sg_nr; j++)
D_FREE(sgls[i].sg_iovs[j].iov_buf);
sgls[i].sg_iovs[j].iov_buf = NULL;
}
}
}

Expand Down Expand Up @@ -3524,15 +3519,11 @@ obj_cpd_reply(crt_rpc_t *rpc, int status, uint32_t map_version)
D_ERROR("Send CPD reply failed: "DF_RC"\n", DP_RC(rc));

cleanup:
if (oco->oco_sub_rets.ca_count != 0) {
D_FREE(oco->oco_sub_rets.ca_arrays);
oco->oco_sub_rets.ca_count = 0;
}
D_FREE(oco->oco_sub_rets.ca_arrays);
oco->oco_sub_rets.ca_count = 0;

if (oco->oco_sub_epochs.ca_count != 0) {
D_FREE(oco->oco_sub_epochs.ca_arrays);
oco->oco_sub_epochs.ca_count = 0;
}
D_FREE(oco->oco_sub_epochs.ca_arrays);
oco->oco_sub_epochs.ca_count = 0;
}

/* Locally process the operations belong to one DTX.
Expand Down

0 comments on commit 3784fcd

Please sign in to comment.