]> git.droids-corp.org - dpdk.git/commitdiff
mem: check allocation in dynamic hugepage init
authorYunjian Wang <wangyunjian@huawei.com>
Tue, 14 Dec 2021 13:30:25 +0000 (21:30 +0800)
committerDavid Marchand <david.marchand@redhat.com>
Fri, 11 Feb 2022 07:46:21 +0000 (08:46 +0100)
The function malloc() could return NULL, the return value
need to be checked.

Fixes: 6f63858e55e6 ("mem: prevent preallocated pages from being freed")
Cc: stable@dpdk.org
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
lib/eal/common/eal_common_dynmem.c

index 7c5437ddfaafab6fec6bd219a697519f7a3907c9..c1e1889f5cd147a8f886ce1ab128ccb11709ecdf 100644 (file)
@@ -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,