Skip to contentSkip to conversation

vhost: fix double free on device stop

PATCH Superseded Michael S. Tsirkin 1 participant 2 messages Jun 21, 2011

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: fix double free on device stop

vhost dev stop failed to clear the log field. Typically not an issue as dev start overwrites this field, but if logging gets disabled before the following start, it doesn't so this causes a double free.

---
 hw/vhost.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
hw/vhost.c +4 -0
index 80f771e..1fbf2e5 100644
@@ -784,5 +784,9 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev)
 
     hdev->started = false;
     qemu_free(hdev->log);
+    if (hdev->log) {
+        qemu_free(hdev->log);
+    }
+    hdev->log = NULL;
     hdev->log_size = 0;
 }
Signature · 1 line
1.7.5.53.gc233e
#1 lore raw
Quoted 6 lines · Michael S. Tsirkin

vhost dev stop failed to clear the log field. Typically not an issue as dev start overwrites this field, but if logging gets disabled before the following start, it doesn't so this causes a double free.

Um, this fixed double free but added another one.
Not sure why did it work for me :(
Sent a fixed v2

Quoted 20 lines
---
 hw/vhost.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
hw/vhost.c +4 -0
index 80f771e..1fbf2e5 100644
@@ -784,5 +784,9 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev)
 
     hdev->started = false;
     qemu_free(hdev->log);
+    if (hdev->log) {
+        qemu_free(hdev->log);
+    }
+    hdev->log = NULL;
     hdev->log_size = 0;
 }
Signature · 1 line
1.7.5.53.gc233e