Skip to contentSkip to conversation

Fixes around qemu_vfree()

PATCH Applied Markus Armbruster 3 participants 7 messages Jan 15, 2013 Block layer

lore
Share & tools
lore
#0 lore raw

v2 cover Fixes around qemu_vfree()

v2: Fix silly mistake in 4/4; the other three patches are unchanged

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
#3 lore raw

PATCH v2 3/4 win32-aio: Fix how win32_aio_process_completion() frees buffer

win32_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
index 46a5db7..0383370 100644
@@ -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
#4 lore raw

PATCH v2 4/4 block: Fix how mirror_run() frees its buffer

In reply to Markus Armbruster

It allocates with qemu_blockalign(), therefore it must free with qemu_vfree(), not g_free().

---
 block/mirror.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/mirror.c +1 -1
index 8aeacbf..6180aa3 100644
@@ -225,7 +225,7 @@ static void coroutine_fn mirror_run(void *opaque)
     }
 
 immediate_exit:
-    g_free(s->buf);
+    qemu_vfree(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
#2 lore raw

PATCH v2 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
index f8d7ef3..96db9a7 100644
@@ -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
#1 lore raw

PATCH v2 1/4 w32: Make qemu_vfree() accept NULL like the POSIX implementation

In reply to Markus Armbruster

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
index e7e283e..640194c 100644
@@ -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
Reviewed-by on the v2 series
#5 lore raw
In reply to Markus Armbruster

Am 15.01.2013 15:29, schrieb Markus Armbruster:

Quoted 8 lines

v2: Fix silly mistake in 4/4; the other three patches are unchanged

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

Quoted 5 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(-)
#6 lore raw
Quoted 9 lines · Kevin Wolf

Am 15.01.2013 15:29, schrieb Markus Armbruster:

Quoted 8 lines

v2: Fix silly mistake in 4/4; the other three patches are unchanged

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

Quoted 7 lines
Quoted 5 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(-)

Thanks, applied Patch 4 to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan