common/mlx5: fix memory leak in Windows MR deregistration
authorMichael Baum <michaelba@nvidia.com>
Wed, 17 Nov 2021 11:02:55 +0000 (13:02 +0200)
committerRaslan Darawsheh <rasland@nvidia.com>
Wed, 17 Nov 2021 14:51:40 +0000 (15:51 +0100)
commitf550a49d499c60ad57d9444f602cb2eb378aa201
tree84db89c6064a72cdc78fe0f563eff96a8936c03e
parente6a6829f9996b1cf066669ad1721b3d04552c048
common/mlx5: fix memory leak in Windows MR deregistration

The "mlx5_devx_cmd_mkey_create" DevX cmd allocates DevX object using
mlx5_malloc and then creates MKey using glue function.
Compatibly, "mlx5_devx_cmd_destroy" cmd releases first the MKey using
glue function, and then free the DevX object using mlx5_free.

On Windows OS, the reg_mr function creates Mkey using
"mlx5_devx_cmd_mkey_create" cmd, but dereg_mr function using directly
glue function without freeing the object.
This behavior causes memory leak at each MR release.

In addition, the dereg_mr function makes sure that the MR pointer is
valid before destroying its fields, but always calls the memset function
that makes a difference to it.

This patch moves the dereg_mr function to use "mlx5_devx_cmd_destroy"
instead of glue function, and extends the validity test to the whole
function.

Fixes: ba420719823c ("common/mlx5: add reg/dereg MR on Windows")
Cc: stable@dpdk.org
Signed-off-by: Michael Baum <michaelba@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
drivers/common/mlx5/windows/mlx5_common_os.c