Skip to contentSkip to conversation

virtio-gpu: use glib alloc/free routines

PATCH New Dave Airlie 1 participant 1 message Dec 10, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-gpu: use glib alloc/free routines

From: Dave Airlie <[email protected]>

Oh I forgot to fix these up previously.

---
 hw/display/virtio-gpu.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
hw/display/virtio-gpu.c +6 -8
index 7bf2fbb..28dcd1e 100644
@@ -137,7 +137,7 @@ static void virtgpu_resource_create_2d(VirtIOGPU *g,
     pixman_format_code_t pformat;
     struct virtgpu_simple_resource *res;
 
-    res = calloc(1, sizeof(struct virtgpu_simple_resource));
+    res = g_new0(struct virtgpu_simple_resource, 1);
     if (!res)
 	return;
 
@@ -159,7 +159,7 @@ static void virtgpu_resource_destroy(struct virtgpu_simple_resource *res)
 {
     pixman_image_unref(res->image);
     QLIST_REMOVE(res, next);
-    free(res);
+    g_free(res);
 }
 
 static void virtgpu_resource_unref(VirtIOGPU *g,
@@ -310,12 +310,10 @@ static void virtgpu_resource_attach_backing(VirtIOGPU *g,
     if (!res)
 	return;
     
-    res_iovs = malloc(att_rb->nr_entries * sizeof(struct iovec));
-    if (!res_iovs)
-	return;
+    res_iovs = g_new0(struct iovec, att_rb->nr_entries);
 
     if (iov_cnt > 1) {
-	data = malloc(gsize);
+	data = g_malloc(gsize);
 	iov_to_buf(iov, iov_cnt, 0, data, gsize);
     } else
 	data = iov[0].iov_base;
@@ -337,7 +335,7 @@ static void virtgpu_resource_attach_backing(VirtIOGPU *g,
     res->iov_cnt = att_rb->nr_entries;
 
     if (iov_cnt > 1)
-	free(data);
+        g_free(data);
 }
 
 static void virtgpu_resource_inval_backing(VirtIOGPU *g,
@@ -354,7 +352,7 @@ static void virtgpu_resource_inval_backing(VirtIOGPU *g,
     for (i = 0; i < res->iov_cnt; i++) {
 	cpu_physical_memory_unmap(res->iov[i].iov_base, res->iov[i].iov_len, 1, res->iov[i].iov_len);
     }
-    free(res->iov);
+    g_free(res->iov);
     res->iov_cnt = 0;
     res->iov = NULL;
 }
Signature · 1 line
1.8.3.1