[dpdk-dev,3/5] malloc: fix potential negative return
Checks
Commit Message
Return from rte_socket_id_by_idx() may be negative, which would
result in negative array index.
Coverity issue: 272590
Fixes: 1403f87d4fb8 ("malloc: enable memory hotplug support")
Cc: anatoly.burakov@intel.com
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
lib/librte_eal/common/malloc_heap.c | 4 ++++
1 file changed, 4 insertions(+)
@@ -563,6 +563,10 @@ malloc_heap_alloc(const char *type, size_t size, int socket_arg,
/* try other heaps */
for (i = 0; i < (int) rte_socket_count(); i++) {
cur_socket = rte_socket_id_by_idx(i);
+ if (cur_socket < 0) {
+ RTE_LOG(ERR, EAL, "Invalid socket index: %i\n", i);
+ continue;
+ }
if (cur_socket == socket)
continue;
ret = heap_alloc_on_socket(type, size, cur_socket, flags,