Message ID | 20210319132527.3118-9-ma.mandourr@gmail.com |
---|---|
State | New |
Headers | show |
Series | virtiofsd: Changed various allocations to GLib functions | expand |
On Fri, Mar 19, 2021 at 03:25:27PM +0200, Mahmoud Mandour wrote: > @@ -588,7 +587,7 @@ out: > } > > pthread_mutex_destroy(&req->ch.lock); > - free(fbuf.mem); > + g_free(fbuf.mem); > free(req); ^--- was FVRequest allocation changed in a previous patch? Maybe an earlier patch forgot to use g_free() here. Aside from this: Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
On Wed, Mar 24, 2021 at 7:12 AM Mahmoud Mandour <ma.mandourr@gmail.com> wrote: > > On Tue, Mar 23, 2021 at 4:15 PM Stefan Hajnoczi <stefanha@gmail.com> wrote: >> >> On Fri, Mar 19, 2021 at 03:25:27PM +0200, Mahmoud Mandour wrote: >> > @@ -588,7 +587,7 @@ out: >> > } >> > >> > pthread_mutex_destroy(&req->ch.lock); >> > - free(fbuf.mem); >> > + g_free(fbuf.mem); >> > free(req); >> >> ^--- was FVRequest allocation changed in a previous patch? >> Maybe an earlier patch forgot to use g_free() here. >> >> Aside from this: >> >> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> > > > I did not change the allocation of FVRequest. I believe that's why > this is left unchanged. Okay, I see it's allocated by libvhost-user and not directly by virtiofsd code. Thanks, Stefan
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); }
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> --- tools/virtiofsd/fuse_virtio.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)