[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 7/7] virtiofsd/fuse_virtio.c: Changed allocations of locals to
From: |
Mahmoud Mandour |
Subject: |
[PATCH v2 7/7] virtiofsd/fuse_virtio.c: Changed allocations of locals to GLib |
Date: |
Tue, 20 Apr 2021 17:46:42 +0200 |
Replaced the allocation of local variables from malloc() to
GLib allocation functions.
In one instance, dropped the usage to an assert after a malloc()
call and used g_malloc() instead.
Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
tools/virtiofsd/fuse_virtio.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
index 5828b9a76f..587403b026 100644
--- a/tools/virtiofsd/fuse_virtio.c
+++ b/tools/virtiofsd/fuse_virtio.c
@@ -472,8 +472,7 @@ static void fv_queue_worker(gpointer data, gpointer
user_data)
* They're spread over multiple descriptors in a scatter/gather set
* and we can't trust the guest to keep them still; so copy in/out.
*/
- fbuf.mem = malloc(se->bufsize);
- assert(fbuf.mem);
+ fbuf.mem = g_malloc(se->bufsize);
fuse_mutex_init(&req->ch.lock);
req->ch.fd = -1;
@@ -524,7 +523,7 @@ static void fv_queue_worker(gpointer data, gpointer
user_data)
fbuf.size = out_sg[0].iov_len + out_sg[1].iov_len;
/* Allocate the bufv, with space for the rest of the iov */
- pbufv = malloc(sizeof(struct fuse_bufvec) +
+ pbufv = g_try_malloc(sizeof(struct fuse_bufvec) +
sizeof(struct fuse_buf) * (out_num - 2));
if (!pbufv) {
fuse_log(FUSE_LOG_ERR, "%s: pbufv malloc failed\n",
@@ -569,7 +568,7 @@ static void fv_queue_worker(gpointer data, gpointer
user_data)
out:
if (allocated_bufv) {
- free(pbufv);
+ g_free(pbufv);
}
/* If the request has no reply, still recycle the virtqueue element */
@@ -588,7 +587,7 @@ out:
}
pthread_mutex_destroy(&req->ch.lock);
- free(fbuf.mem);
+ g_free(fbuf.mem);
free(req);
}
--
2.25.1
- Re: [PATCH v2 2/7] virtiofds: Changed allocations of iovec to GLib's functions, (continued)
- Re: [PATCH v2 2/7] virtiofds: Changed allocations of iovec to GLib's functions, Dr. David Alan Gilbert, 2021/04/27
- Re: [PATCH v2 2/7] virtiofds: Changed allocations of iovec to GLib's functions, Mahmoud Mandour, 2021/04/27
- Re: [PATCH v2 2/7] virtiofds: Changed allocations of iovec to GLib's functions, Dr. David Alan Gilbert, 2021/04/27
- [PATCH v3 2/7] virtiofsd: Changed allocations of iovec to GLib's functions, Mahmoud Mandour, 2021/04/27
- Re: [PATCH v2 2/7] virtiofds: Changed allocations of iovec to GLib's functions, Mahmoud Mandour, 2021/04/27
- Re: [PATCH v2 2/7] virtiofds: Changed allocations of iovec to GLib's functions, Dr. David Alan Gilbert, 2021/04/27
- Re: [PATCH v2 2/7] virtiofds: Changed allocations of iovec to GLib's functions, Daniel P . Berrangé, 2021/04/27
[PATCH v2 3/7] virtiofsd: Changed allocations of fuse_session to GLib's functions, Mahmoud Mandour, 2021/04/20
[PATCH v2 4/7] virtiofsd: Changed allocation of lo_map_elems to GLib's functions, Mahmoud Mandour, 2021/04/20
[PATCH v2 6/7] virtiofsd/passthrough_ll.c: Changed local allocations to GLib functions, Mahmoud Mandour, 2021/04/20
[PATCH v2 7/7] virtiofsd/fuse_virtio.c: Changed allocations of locals to GLib,
Mahmoud Mandour <=
[PATCH v2 5/7] virtiofsd: Changed allocations of fv_VuDev & its internals to GLib functions, Mahmoud Mandour, 2021/04/20