From 329ea42d73c3468dbb8e69060f4a13022988f3f6 Mon Sep 17 00:00:00 2001 From: Yin Fengwei Date: Wed, 19 Dec 2018 17:13:03 +0800 Subject: [PATCH] dm: fix the memory leak in virtio mei The possible memory leak was introduced by commit 7fce2462a0df5e3ab767103026cc0139e606facf If mevent add fails in virtio mei, the resource allocated doesn't be released. This patch fix this memory leak issue. Tracked-On: #1877 Signed-off-by: Yin Fengwei --- devicemodel/hw/pci/virtio/virtio_mei.c | 32 +++++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/devicemodel/hw/pci/virtio/virtio_mei.c b/devicemodel/hw/pci/virtio/virtio_mei.c index 366b78c27..17f991098 100644 --- a/devicemodel/hw/pci/virtio/virtio_mei.c +++ b/devicemodel/hw/pci/virtio/virtio_mei.c @@ -373,6 +373,20 @@ vmei_set_status(struct virtio_mei *vmei, enum vmei_status status) vmei->status = status; } +static void +vmei_rx_teardown(void *param) +{ + unsigned int i; + struct vmei_host_client *hclient = param; + + if (hclient->client_fd > -1) + close(hclient->client_fd); + for (i = 0; i < VMEI_IOBUFS_MAX; i++) + free(hclient->send_bufs.bufs[i].iov_base); + free(hclient->recv_buf); + free(hclient); +} + static void vmei_host_client_destroy(const struct refcnt *ref) { @@ -389,20 +403,8 @@ vmei_host_client_destroy(const struct refcnt *ref) if (hclient->rx_mevp) mevent_delete(hclient->rx_mevp); -} - -static void -vmei_rx_teardown(void *param) -{ - unsigned int i; - struct vmei_host_client *hclient = param; - - if (hclient->client_fd > -1) - close(hclient->client_fd); - for (i = 0; i < VMEI_IOBUFS_MAX; i++) - free(hclient->send_bufs.bufs[i].iov_base); - free(hclient->recv_buf); - free(hclient); + else + vmei_rx_teardown(hclient); } static struct vmei_host_client * @@ -977,6 +979,8 @@ static void vmei_del_reset_event(struct virtio_mei *vmei) { if (vmei->reset_mevp) mevent_delete_close(vmei->reset_mevp); + else + vmei_reset_teardown(vmei); } static void vmei_rx_callback(int fd, enum ev_type type, void *param);