From 8dfb09dee47b78463af75d343b03e93f8324c6e4 Mon Sep 17 00:00:00 2001 From: Anatoly Burakov Date: Mon, 16 Apr 2018 16:37:03 +0100 Subject: [PATCH] mem: fix potential resource leak on alloc Normally, tailq entry should have a valid fd by the time we attempt to map the segment. However, in case it doesn't, we're leaking fd, so fix it. Coverity issue: 272570 Fixes: 2a04139f66b4 ("eal: add single file segments option") Signed-off-by: Anatoly Burakov --- lib/librte_eal/linuxapp/eal/eal_memalloc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c index f36929760b..6f0eda5d8f 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c +++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c @@ -522,13 +522,14 @@ resized: resize_hugefile(fd, map_offset, alloc_sz, false); if (is_zero_length(fd)) { struct msl_entry *te = get_msl_entry_by_idx(list_idx); - if (te != NULL && te->fd >= 0) { - close(te->fd); + /* te->fd is equivalent to fd */ + if (te != NULL && te->fd >= 0) te->fd = -1; - } /* ignore errors, can't make it any worse */ unlink(path); + close(fd); } + /* if we're not removing the file, fd stays in the tailq */ } else { close(fd); unlink(path); -- 2.20.1