Skip to content

Commit 8ef43b0

Browse files
committed
mlx5: vfio: fix memory leak in mlx5_vfio_get_iommu_info
[ Upstream commit f6346c2 ] If realloc fails, info pointers is being set to NULL although its original memory has not been freed. Use a temporary pointer to be able to free the original memory in case realloc fails. Fixes: bfc56ce ("mlx5: Setup mlx5 vfio context") Signed-off-by: Nicolas Morey <[email protected]>
1 parent d81e886 commit 8ef43b0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

providers/mlx5/mlx5_vfio.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,12 +1040,15 @@ static int mlx5_vfio_get_iommu_info(struct mlx5_vfio_context *ctx)
10401040
goto end;
10411041

10421042
if (info->argsz > sizeof(*info)) {
1043-
info = realloc(info, info->argsz);
1044-
if (!info) {
1043+
struct vfio_iommu_type1_info *tmp;
1044+
1045+
tmp = realloc(info, info->argsz);
1046+
if (!tmp) {
10451047
errno = ENOMEM;
10461048
ret = -1;
10471049
goto end;
10481050
}
1051+
info = tmp;
10491052

10501053
ret = ioctl(ctx->container_fd, VFIO_IOMMU_GET_INFO, info);
10511054
if (ret)

0 commit comments

Comments
 (0)