diff mbox

[1/2] virtio: fix memory leak on device removal

Message ID 20090721155909.GB3306@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michael S. Tsirkin July 21, 2009, 3:59 p.m. UTC
Free up msi vector tables.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/virtio/virtio_pci.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

Comments

Rusty Russell July 23, 2009, 4:26 a.m. UTC | #1
On Wed, 22 Jul 2009 01:29:09 am Michael S. Tsirkin wrote:
> Free up msi vector tables.

Michael, this papers over the bug, but doesn't actually fix the problem.

The problem is that vp_free_vectors() does not do the reverse of 
vp_request_vectors.  If the author (you) can't get it right, what hope the 
rest of us?

Indeed, if you look harder, you'll see another leak caused by this problem, 
which your patch *didn't* fix.

Thanks,
Rusty.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Michael S. Tsirkin July 23, 2009, 10:27 a.m. UTC | #2
On Thu, Jul 23, 2009 at 01:56:58PM +0930, Rusty Russell wrote:
> On Wed, 22 Jul 2009 01:29:09 am Michael S. Tsirkin wrote:
> > Free up msi vector tables.
> 
> Michael, this papers over the bug, but doesn't actually fix the problem.
> 
> The problem is that vp_free_vectors() does not do the reverse of 
> vp_request_vectors.  If the author (you) can't get it right, what hope the 
> rest of us?

I agree. This code belongs in free_vectors.
And might as well reset the pointers to make the reversal complete.

> Indeed, if you look harder, you'll see another leak caused by this problem, 
> which your patch *didn't* fix.

Couldn't spot it yet. I'll send out a fixed patch, see if I got
everything covered.

> Thanks,
> Rusty.
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index 193c8f0..dab3c86 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -489,12 +489,15 @@  static void vp_del_vq(struct virtqueue *vq)
 /* the config->del_vqs() implementation */
 static void vp_del_vqs(struct virtio_device *vdev)
 {
+	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
 	struct virtqueue *vq, *n;
 
 	list_for_each_entry_safe(vq, n, &vdev->vqs, list)
 		vp_del_vq(vq);
 
 	vp_free_vectors(vdev);
+	kfree(vp_dev->msix_names);
+	kfree(vp_dev->msix_entries);
 }
 
 /* the config->find_vqs() implementation */