diff --git a/fabtests/prov/efa/src/efa_exhaust_mr_reg_common.c b/fabtests/prov/efa/src/efa_exhaust_mr_reg_common.c index e8a680ea7a4..29090e7602b 100644 --- a/fabtests/prov/efa/src/efa_exhaust_mr_reg_common.c +++ b/fabtests/prov/efa/src/efa_exhaust_mr_reg_common.c @@ -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) diff --git a/fabtests/prov/efa/src/efa_exhaust_mr_reg_common.h b/fabtests/prov/efa/src/efa_exhaust_mr_reg_common.h index 867d4c36dbe..68a33ddb5aa 100644 --- a/fabtests/prov/efa/src/efa_exhaust_mr_reg_common.h +++ b/fabtests/prov/efa/src/efa_exhaust_mr_reg_common.h @@ -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 */ diff --git a/fabtests/prov/efa/src/efa_exhaust_mr_reg_rdm_pingpong.c b/fabtests/prov/efa/src/efa_exhaust_mr_reg_rdm_pingpong.c index fe49df3b36e..9cde8bc43a3 100644 --- a/fabtests/prov/efa/src/efa_exhaust_mr_reg_rdm_pingpong.c +++ b/fabtests/prov/efa/src/efa_exhaust_mr_reg_rdm_pingpong.c @@ -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; @@ -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); @@ -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();