dm: fix the memory leak in virtio mei

The possible memory leak was introduced by commit
7fce2462a0

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>
This commit is contained in:
Yin Fengwei 2018-12-19 17:13:03 +08:00 committed by wenlingz
parent 8f57c61da9
commit 329ea42d73
1 changed files with 18 additions and 14 deletions

View File

@ -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);