Skip to content

Commit

Permalink
fabtests/efa: Fix memory leaks for efa_exhaust_mr_reg test
Browse files Browse the repository at this point in the history
1. The array of buffers needs to be freed individually during
cleanup.
2. buffers and mr_reg_vec should only be freed when they were
alloced (client).

Signed-off-by: Shi Jin <[email protected]>
  • Loading branch information
shijin-aws committed May 7, 2024
1 parent 0bf67ce commit f41cea5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
19 changes: 16 additions & 3 deletions fabtests/prov/efa/src/efa_exhaust_mr_reg_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,29 @@ int ft_efa_deregister_mr_reg(struct ibv_mr **mr_reg_vec, size_t count)
return err;
}

int ft_efa_alloc_bufs(void **buffers, size_t buf_size, size_t count) {
int ft_efa_alloc_bufs(void **buffers, size_t buf_size, size_t count, size_t *alloced) {
int i;
int ret = FI_SUCCESS;

for (i = 0; i < count; i++) {
buffers[i] = malloc(buf_size);
if (!buffers[i]) {
FT_ERR("malloc failed!\n");
return EXIT_FAILURE;
ret = EXIT_FAILURE;
goto out;
}
}
return FI_SUCCESS;

out:
*alloced = i;
return ret;
}

void ft_efa_free_bufs(void **buffers, size_t count) {
int i;

for (i = 0; i < count; i++)
free(buffers[i]);
}

int ft_efa_unexpected_pingpong(void)
Expand Down
3 changes: 2 additions & 1 deletion fabtests/prov/efa/src/efa_exhaust_mr_reg_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ void ft_efa_destroy_ibv_pd(struct ibv_pd *pd);
int ft_efa_register_mr_reg(struct ibv_pd *pd, void **buffers, size_t buf_size,
struct ibv_mr **mr_reg_vec, size_t count, size_t *registered);
int ft_efa_deregister_mr_reg(struct ibv_mr **mr_reg_vec, size_t count);
int ft_efa_alloc_bufs(void **buffers, size_t buf_size, size_t count);
int ft_efa_alloc_bufs(void **buffers, size_t buf_size, size_t count, size_t *alloced);
void ft_efa_free_bufs(void **buffers, size_t count);
int ft_efa_unexpected_pingpong(void);

#endif /* _EFA_EXHAUST_MR_REG_COMMON_H */
9 changes: 5 additions & 4 deletions fabtests/prov/efa/src/efa_exhaust_mr_reg_rdm_pingpong.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ int main(int argc, char **argv)
{
int op, ret, err, mr_reg_limit;
size_t registered;
size_t alloced;
void **buffers = NULL;
struct ibv_mr **mr_reg_vec = NULL;
struct ibv_context *ibv_ctx = NULL;
Expand Down Expand Up @@ -108,7 +109,7 @@ int main(int argc, char **argv)

printf("Exhausting MRs on client\n");
err = ft_efa_alloc_bufs(buffers, EFA_MR_REG_BUF_SIZE,
mr_reg_limit);
mr_reg_limit, &alloced);
if (err)
FT_PRINTERR("alloc bufs", -err);

Expand All @@ -134,13 +135,13 @@ int main(int argc, char **argv)
err = ft_efa_deregister_mr_reg(mr_reg_vec, registered);
if (err)
FT_PRINTERR("ibv mr dereg", -err);
ft_efa_free_bufs(buffers, alloced);
free(buffers);
free(mr_reg_vec);
ft_efa_destroy_ibv_pd(pd);
ft_efa_close_ibv_device(ibv_ctx);
}

free(buffers);
free(mr_reg_vec);

ft_finalize();
ft_free_res();

Expand Down

0 comments on commit f41cea5

Please sign in to comment.