vppinfra: introduce clib_mem_vm_ext_free() to avoid fd leaks
Change-Id: I8691a10493d159a97574550c111f07722960a7cd Signed-off-by: Haiyang Tan <haiyangtan@tencent.com>
This commit is contained in:

committed by
Damjan Marion

parent
cd80692dfc
commit
642829de79
@ -132,7 +132,7 @@ check_hugetlb:
|
||||
goto error;
|
||||
}
|
||||
else
|
||||
clib_mem_vm_free (alloc.addr, 1 << alloc.log2_page_size);
|
||||
clib_mem_vm_ext_free (&alloc);
|
||||
|
||||
goto done;
|
||||
|
||||
|
@ -252,6 +252,17 @@ done:
|
||||
return err;
|
||||
}
|
||||
|
||||
void
|
||||
clib_mem_vm_ext_free (clib_mem_vm_alloc_t * a)
|
||||
{
|
||||
if (a != 0)
|
||||
{
|
||||
clib_mem_vm_free (a->addr, 1 << a->log2_page_size);
|
||||
if (a->fd != -1)
|
||||
close (a->fd);
|
||||
}
|
||||
}
|
||||
|
||||
u64 *
|
||||
clib_mem_vm_get_paddr (void *mem, int log2_page_size, int n_pages)
|
||||
{
|
||||
|
@ -387,6 +387,7 @@ typedef struct
|
||||
} clib_mem_vm_alloc_t;
|
||||
|
||||
clib_error_t *clib_mem_vm_ext_alloc (clib_mem_vm_alloc_t * a);
|
||||
void clib_mem_vm_ext_free (clib_mem_vm_alloc_t * a);
|
||||
u64 clib_mem_vm_get_page_size (int fd);
|
||||
int clib_mem_vm_get_log2_page_size (int fd);
|
||||
u64 *clib_mem_vm_get_paddr (void *mem, int log2_page_size, int n_pages);
|
||||
|
Reference in New Issue
Block a user