Skip to content

Commit

Permalink
dm: fix the memory leak in virtio mei
Browse files Browse the repository at this point in the history
The possible memory leak was introduced by commit
7fce246

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 <fengwei.yin@intel.com>
  • Loading branch information
fyin1 authored and wenlingz committed Dec 27, 2018
1 parent 8f57c61 commit 329ea42
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions devicemodel/hw/pci/virtio/virtio_mei.c
Expand Up @@ -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)
{
Expand All @@ -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 *
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 329ea42

Please sign in to comment.