Skip to contentSkip to conversation

Fixes around qemu_vfree()

PATCH Applied Markus Armbruster 4 participants 12 messages Jan 15, 2013 Block layer

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

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

PATCH 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().

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
index 8aeacbf..27a7d8c 100644
@@ -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
#2 lore raw

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

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

In reply to Markus Armbruster

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

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 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 +0 -0
index 46a5db7..0383370 100644

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

#7 lore raw

Re: [Qemu-devel] [PATCH 4/4] block: Fix how mirror_run() frees its buffer

In reply to Markus Armbruster

Am 15.01.2013 14:23, schrieb Markus Armbruster:

Quoted 5 lines

It 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.

...except that it's now leaked for all error cases but the first.

Kevin

Quoted 21 lines
---
 block/mirror.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/mirror.c +1 -1
index 8aeacbf..27a7d8c 100644
@@ -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) {
Reviewed-by on the v1 series
#10 lore raw
In reply to Markus Armbruster

Am 15.01.2013 14:23, schrieb Markus Armbruster:

Quoted 11 lines

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(-)

Patches 1-3:

#8 lore raw

Re: [Qemu-devel] [PATCH 4/4] block: Fix how mirror_run() frees its buffer

In reply to Kevin Wolf
Quoted 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 with qemu_vfree(), not g_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.

Acked-by on v1 2/4
#3 lore raw

Re: [Qemu-devel] [PATCH 2/4] scsi-disk: qemu_vfree(NULL) is fine, simplify

In reply to Markus Armbruster

Il 15/01/2013 14:23, Markus Armbruster ha scritto:

Quoted 11 lines
---
 hw/scsi-disk.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/scsi-disk.c +0 -0
index f8d7ef3..96db9a7 100644

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.  */
#9 lore raw

Re: [Qemu-devel] [PATCH 4/4] block: Fix how mirror_run() frees its buffer

In reply to Markus Armbruster

Il 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 with qemu_vfree(), not g_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

#11 lore raw
In reply to Markus Armbruster
Quoted 6 lines · Markus Armbruster

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 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