Skip to contentSkip to conversation

win32: pair qemu_memalign() with qemu_vfree()

PATCH Applied Herve Poussineau 2 participants 2 messages Jan 24, 2010 – Jan 27, 2010 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 win32: pair qemu_memalign() with qemu_vfree()

Win32 suffers from a very big memory leak when dealing with SCSI devices. Each read/write request allocates memory with qemu_memalign (ie VirtualAlloc) but frees it with qemu_free (ie free).
Pair all qemu_memalign() calls with qemu_vfree() to prevent such leaks.

---
 block.c           |    2 +-
 block/raw-posix.c |    2 +-
 exec.c            |    2 +-
 hw/scsi-disk.c    |    2 +-
 qemu-nbd.c        |    2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)
block.c +1 -1
index 73c26ec..6e440b7 100644
@@ -1629,7 +1629,7 @@ static void multiwrite_user_cb(MultiwriteCB *mcb)
     for (i = 0; i < mcb->num_callbacks; i++) {
         mcb->callbacks[i].cb(mcb->callbacks[i].opaque, mcb->error);
         qemu_free(mcb->callbacks[i].free_qiov);
-        qemu_free(mcb->callbacks[i].free_buf);
+        qemu_vfree(mcb->callbacks[i].free_buf);
     }
 }
 
block/raw-posix.c +1 -1
index 52bbcda..b4ff841 100644
@@ -595,7 +595,7 @@ static void raw_close(BlockDriverState *bs)
         close(s->fd);
         s->fd = -1;
         if (s->aligned_buf != NULL)
-            qemu_free(s->aligned_buf);
+            qemu_vfree(s->aligned_buf);
     }
 }
 
exec.c +1 -1
index 1190591..76831a1 100644
@@ -3309,7 +3309,7 @@ void cpu_physical_memory_unmap(void *buffer, target_phys_addr_t len,
     if (is_write) {
         cpu_physical_memory_write(bounce.addr, bounce.buffer, access_len);
     }
-    qemu_free(bounce.buffer);
+    qemu_vfree(bounce.buffer);
     bounce.buffer = NULL;
     cpu_notify_map_clients();
 }
hw/scsi-disk.c +1 -1
index e3924de..b34fbaa 100644
@@ -81,7 +81,7 @@ static SCSIDiskReq *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun)
 
 static void scsi_remove_request(SCSIDiskReq *r)
 {
-    qemu_free(r->iov.iov_base);
+    qemu_vfree(r->iov.iov_base);
     scsi_req_free(&r->req);
 }
 
qemu-nbd.c +1 -1
index 4463679..eac0c21 100644
@@ -469,7 +469,7 @@ int main(int argc, char **argv)
             }
         }
     } while (persistent || nb_fds > 1);
-    qemu_free(data);
+    qemu_vfree(data);
 
     close(sharing_fds[0]);
     bdrv_close(bs);
Signature · 1 line
1.6.0.2.GIT
#1 lore raw
Quoted 7 lines · Herve Poussineau

Win32 suffers from a very big memory leak when dealing with SCSI devices. Each read/write request allocates memory with qemu_memalign (ie VirtualAlloc) but frees it with qemu_free (ie free).
Pair all qemu_memalign() calls with qemu_vfree() to prevent such leaks.

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 74 lines
---
  block.c           |    2 +-
  block/raw-posix.c |    2 +-
  exec.c            |    2 +-
  hw/scsi-disk.c    |    2 +-
  qemu-nbd.c        |    2 +-
  5 files changed, 5 insertions(+), 5 deletions(-)
block.c +1 -1
index 73c26ec..6e440b7 100644
@@ -1629,7 +1629,7 @@ static void multiwrite_user_cb(MultiwriteCB *mcb)
      for (i = 0; i<  mcb->num_callbacks; i++) {
          mcb->callbacks[i].cb(mcb->callbacks[i].opaque, mcb->error);
          qemu_free(mcb->callbacks[i].free_qiov);
-        qemu_free(mcb->callbacks[i].free_buf);
+        qemu_vfree(mcb->callbacks[i].free_buf);
      }
  }
 
block/raw-posix.c +1 -1
index 52bbcda..b4ff841 100644
@@ -595,7 +595,7 @@ static void raw_close(BlockDriverState *bs)
          close(s->fd);
          s->fd = -1;
          if (s->aligned_buf != NULL)
-            qemu_free(s->aligned_buf);
+            qemu_vfree(s->aligned_buf);
      }
  }
 
exec.c +1 -1
index 1190591..76831a1 100644
@@ -3309,7 +3309,7 @@ void cpu_physical_memory_unmap(void *buffer, target_phys_addr_t len,
      if (is_write) {
          cpu_physical_memory_write(bounce.addr, bounce.buffer, access_len);
      }
-    qemu_free(bounce.buffer);
+    qemu_vfree(bounce.buffer);
      bounce.buffer = NULL;
      cpu_notify_map_clients();
  }
hw/scsi-disk.c +1 -1
index e3924de..b34fbaa 100644
@@ -81,7 +81,7 @@ static SCSIDiskReq *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun)
 
  static void scsi_remove_request(SCSIDiskReq *r)
  {
-    qemu_free(r->iov.iov_base);
+    qemu_vfree(r->iov.iov_base);
      scsi_req_free(&r->req);
  }
 
qemu-nbd.c +1 -1
index 4463679..eac0c21 100644
@@ -469,7 +469,7 @@ int main(int argc, char **argv)
              }
          }
      } while (persistent || nb_fds>  1);
-    qemu_free(data);
+    qemu_vfree(data);
 
      close(sharing_fds[0]);
      bdrv_close(bs);