Fixes around qemu_vfree()
cover Fixes around qemu_vfree()
Markus Armbruster (4):
w32: Make qemu_vfree() accept NULL like the POSIX implementation
scsi-disk: qemu_vfree(NULL) is fine, simplify
win32-aio: Fix how win32_aio_process_completion() frees buffer
block: Fix how mirror_run() frees its buffer
block/mirror.c | 2 +- block/win32-aio.c | 2 +- hw/scsi-disk.c | 4 +--- util/oslib-win32.c | 4 +++- 4 files changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
1.7.11.7
PATCH 1/4 w32: Make qemu_vfree() accept NULL like the POSIX implementation
On POSIX, qemu_vfree() accepts NULL, because it's merely wrapper around free(). As far as I can tell, the Windows implementation doesn't. Breeds bugs that bite only under Windows.
Make the Windows implementation behave like the POSIX implementation.
--- util/oslib-win32.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
util/oslib-win32.c +3 -1
@@ -71,7 +71,9 @@ void *qemu_vmalloc(size_t size)void qemu_vfree (void *ptr) {trace_qemu_vfree (ptr); -VirtualFree (ptr,0 ,MEM_RELEASE ); +if (ptr) { +VirtualFree (ptr,0 ,MEM_RELEASE ); + } }/* FIXME: add proper locking */
Signature · 1 line
1.7.11.7
PATCH 4/4 block: Fix how mirror_run() frees its buffer
In reply to Markus ArmbrusterIt allocates with qemu_blockalign(), therefore it must free with qemu_vfree(), not g_free().
Since I'm touching it anyway, move the free to a more obviosly correct place.
--- block/mirror.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/mirror.c +1 -1
@@ -223,9 +223,9 @@ static void coroutine_fn mirror_run(void *opaque)break ; } } +qemu_vfree (s->buf); immediate_exit: -g_free (s->buf);bdrv_set_dirty_tracking (bs, false);bdrv_iostatus_disable (s->target);if (s->should_complete && ret ==0 ) {
Signature · 1 line
1.7.11.7
PATCH 2/4 scsi-disk: qemu_vfree(NULL) is fine, simplify
In reply to Markus Armbruster--- hw/scsi-disk.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
hw/scsi-disk.c +1 -3
@@ -85,9 +85,7 @@ static void scsi_free_request(SCSIRequest *req) {SCSIDiskReq *r =DO_UPCAST (SCSIDiskReq, req, req); -if (r->iov.iov_base) { -qemu_vfree (r->iov.iov_base); - } +qemu_vfree (r->iov.iov_base); }/* Helper function for command completion with sense. */
Signature · 1 line
1.7.11.7
PATCH 3/4 win32-aio: Fix how win32_aio_process_completion() frees buffer
In reply to Markus Armbrusterwin32_aio_submit() allocates it with qemu_blockalign(), therefore it must be freed with qemu_vfree(), not g_free().
--- block/win32-aio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/win32-aio.c +1 -1
@@ -87,7 +87,7 @@ static void win32_aio_process_completion(QEMUWin32AIOState *s,memcpy (p, qiov->iov[i].iov_base, qiov->iov[i].iov_len); p += qiov->iov[i].iov_len; } -g_free (waiocb->buf); +qemu_vfree (waiocb->buf); } }
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 3/4] win32-aio: Fix how win32_aio_process_completion() frees buffer
Am 15.01.2013 14:23, schrieb Markus Armbruster:
Quoted 13 lines
win32_aio_submit()allocates it withqemu_blockalign(), therefore it must be freed withqemu_vfree(), notg_free().Signed-off-by Markus Armbruster <[email protected]>--- block/win32-aio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/win32-aio.c +0
-0
block/win32-aio.c static void win32_aio_process_completion(QEMUWin32AIOState *s, · line 92
Quoted 7 lines
block/win32-aio.c +1
-1@@ -87,7 +87,7 @@ static void win32_aio_process_completion(QEMUWin32AIOState *s,memcpy (p, qiov->iov[i].iov_base, qiov->iov[i].iov_len); p += qiov->iov[i].iov_len; } -g_free (waiocb->buf); +qemu_vfree (waiocb->buf); } }
Independent bug: waiocb->buf is leaked for writes and failed reads.
Kevin
Re: [Qemu-devel] [PATCH 4/4] block: Fix how mirror_run() frees its buffer
In reply to Markus ArmbrusterAm 15.01.2013 14:23, schrieb Markus Armbruster:
Quoted 5 lines
It allocates with
qemu_blockalign(), therefore it must free withqemu_vfree(), notg_free().Since I'm touching it anyway, move the free to a more obviosly correct place.
...except that it's now leaked for all error cases but the first.
Kevin
Quoted 21 lines
Signed-off-by Markus Armbruster <[email protected]>--- block/mirror.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/mirror.c +1
-1@@ -223,9 +223,9 @@ static void coroutine_fn mirror_run(void *opaque)break ; } } +qemu_vfree (s->buf); immediate_exit: -g_free (s->buf);bdrv_set_dirty_tracking (bs, false);bdrv_iostatus_disable (s->target);if (s->should_complete && ret ==0 ) {
Am 15.01.2013 14:23, schrieb Markus Armbruster:
Quoted 11 lines
Markus Armbruster (4):
w32: Makeqemu_vfree()accept NULL like the POSIX implementation
scsi-disk:qemu_vfree(NULL)is fine, simplify
win32-aio: Fix howwin32_aio_process_completion()frees buffer
block: Fix howmirror_run()frees its bufferblock/mirror.c | 2 +- block/win32-aio.c | 2 +- hw/scsi-disk.c | 4 +--- util/oslib-win32.c | 4 +++- 4 files changed, 6 insertions(+), 6 deletions(-)
Patches 1-3:
Re: [Qemu-devel] [PATCH 4/4] block: Fix how mirror_run() frees its buffer
In reply to Kevin WolfQuoted 8 lines · Kevin Wolf
Am 15.01.2013 14:23, schrieb Markus Armbruster:
Quoted 5 lines
It allocates with
qemu_blockalign(), therefore it must free withqemu_vfree(), notg_free().Since I'm touching it anyway, move the free to a more obviosly correct place.
...except that it's now leaked for all error cases but the first.
Brain fart caused by looking at the RHEL code, will respin.
Re: [Qemu-devel] [PATCH 2/4] scsi-disk: qemu_vfree(NULL) is fine, simplify
In reply to Markus ArmbrusterIl 15/01/2013 14:23, Markus Armbruster ha scritto:
Quoted 11 lines
Signed-off-by Markus Armbruster <[email protected]>--- hw/scsi-disk.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)hw/scsi-disk.c +0
-0
hw/scsi-disk.c static void scsi_free_request(SCSIRequest *req) · line 91
Quoted 10 lines
hw/scsi-disk.c +1
-3@@ -85,9 +85,7 @@ static void scsi_free_request(SCSIRequest *req) {SCSIDiskReq *r =DO_UPCAST (SCSIDiskReq, req, req); -if (r->iov.iov_base) { -qemu_vfree (r->iov.iov_base); - } +qemu_vfree (r->iov.iov_base); }/* Helper function for command completion with sense. */
Re: [Qemu-devel] [PATCH 4/4] block: Fix how mirror_run() frees its buffer
In reply to Markus ArmbrusterIl 15/01/2013 15:20, Markus Armbruster ha scritto:
Quoted 11 lines
Quoted 8 lines
Quoted 8 lines
Am 15.01.2013 14:23, schrieb Markus Armbruster:
Quoted 5 lines
Quoted 5 lines
It allocates with
qemu_blockalign(), therefore it must free withqemu_vfree(), notg_free().Since I'm touching it anyway, move the free to a more obviosly correct place.
...except that it's now leaked for all error cases but the first.
Brain fart caused by looking at the RHEL code, will respin.
I'll pick this in my own mirror series, if you don't mind.
Paolo
Stefan Hajnoczi
AppliedQuoted 6 lines · Markus Armbruster
Markus Armbruster (4):
w32: Makeqemu_vfree()accept NULL like the POSIX implementation
scsi-disk:qemu_vfree(NULL)is fine, simplify
win32-aio: Fix howwin32_aio_process_completion()frees buffer
block: Fix howmirror_run()frees its buffer
Quoted 9 lines
block/mirror.c | 2 +- block/win32-aio.c | 2 +- hw/scsi-disk.c | 4 +--- util/oslib-win32.c | 4 +++- 4 files changed, 6 insertions(+), 6 deletions(-)Signature · 1 line
1.7.11.7
Thanks, applied Patch 1-3 to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan