Skip to content

Commit

Permalink
mem: check allocation in dynamic hugepage init
Browse files Browse the repository at this point in the history
[ upstream commit 5f69ebb ]

The function malloc() could return NULL, the return value
need to be checked.

Fixes: 6f63858 ("mem: prevent preallocated pages from being freed")

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
  • Loading branch information
wyjwang authored and bluca committed Feb 17, 2022
1 parent c7bd2f4 commit 1b84be5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/librte_eal/common/eal_common_dynmem.c
Expand Up @@ -304,6 +304,10 @@ eal_dynmem_hugepage_init(void)
needed = num_pages - num_pages_alloc;

pages = malloc(sizeof(*pages) * needed);
if (pages == NULL) {
RTE_LOG(ERR, EAL, "Failed to malloc pages\n");
return -1;
}

/* do not request exact number of pages */
cur_pages = eal_memalloc_alloc_seg_bulk(pages,
Expand Down

0 comments on commit 1b84be5

Please sign in to comment.