vhost fix potential memleak in vhost_backend_cleanup

dev->mem_table_fds init in vhost_user_set_mem_table
but dev->mem may init later in vhost_user_set_vring_addr,
so if qemu crash or lost conntion after vhost_user_set_mem_table
and before vhost_user_set_vring_addr,
it's hugepage memory is not being freed

Signed-off-by: Honghui Wang <wanghonghui@ucloud.cn>
Change-Id: I782c106078829ff6691ed3265a5d1718493de90c
Reviewed-on: https://review.gerrithub.io/c/440254
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
wanghonghui 2019-01-11 18:47:17 +08:00 committed by Jim Harris
parent 5977aad8f7
commit 554aaffe3b

View File

@ -120,13 +120,13 @@ vhost_backend_cleanup(struct virtio_net *dev)
{
uint32_t i;
if (dev->mem) {
if (dev->has_new_mem_table) {
for (i = 0; i < dev->mem->nregions; i++) {
close(dev->mem_table_fds[i]);
}
dev->has_new_mem_table = 0;
if (dev->has_new_mem_table) {
for (i = 0; i < dev->mem_table.nregions; i++) {
close(dev->mem_table_fds[i]);
}
dev->has_new_mem_table = 0;
}
if (dev->mem) {
free_mem_region(dev);
rte_free(dev->mem);
dev->mem = NULL;