[PATCH 11/25] plugins/amdgpu: Fix error handling in amdgpu_plugin_drm_restore_file()

Tvrtko Ursulin <[email protected]> Wed, 11 Mar 2026 09:59:00 +0000
Newsgroups dev.linux.lists.criu
Message-ID <[email protected]>
Add missing error checking for failure to allocate memory, plus, actually
free the memory on the failure exit path.

Signed-off-by: Tvrtko Ursulin <[email protected]>
Reviewed-By: David Francis <[email protected]>
---
 plugins/amdgpu/amdgpu_plugin_drm.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/plugins/amdgpu/amdgpu_plugin_drm.c b/plugins/amdgpu/amdgpu_plugin_drm.c
index 06976a81ce1a..9df755450dc9 100644
--- a/plugins/amdgpu/amdgpu_plugin_drm.c
+++ b/plugins/amdgpu/amdgpu_plugin_drm.c
@@ -454,8 +454,13 @@ int amdgpu_plugin_drm_restore_file(int fd, CriuRenderNode *rd)
 	bool retry_needed = false;
 	uint32_t major, minor;
 	amdgpu_device_handle h_dev;
-	int device_fd;
-	int *dmabufs = xzalloc(sizeof(int) * rd->num_of_bos);
+	int device_fd, *dmabufs;
+
+	dmabufs = xzalloc(sizeof(int) * rd->num_of_bos);
+	if (!dmabufs) {
+		pr_err("Failed allocate memory for drm restore\n");
+		return -ENOMEM;
+	}
 
 	ret = amdgpu_device_initialize(fd, &major, &minor, &h_dev);
 	if (ret) {
@@ -573,9 +578,9 @@ int amdgpu_plugin_drm_restore_file(int fd, CriuRenderNode *rd)
 	}
 
 exit:
-	if (ret < 0)
-		return ret;
 	xfree(dmabufs);
+	if (ret < 0)
+		return ret;
 
 	return retry_needed;
 }
-- 
2.52.0