From a7209c2dbc2b26947ea8807283f0377d3d83452c Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 21 Apr 2023 09:12:08 -0400 Subject: [PATCH] lib: Make coverity happy about close The error condition handled both failure to open and a fstat failure. Just double check that the close is appropriate to call. Signed-off-by: Donald Sharp --- lib/elf_py.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/elf_py.c b/lib/elf_py.c index 05f5aef766..d473dc10cb 100644 --- a/lib/elf_py.c +++ b/lib/elf_py.c @@ -1140,7 +1140,8 @@ static PyObject *elffile_load(PyTypeObject *type, PyObject *args, fd = open(filename, O_RDONLY | O_NOCTTY); if (fd < 0 || fstat(fd, &st)) { PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename); - close(fd); + if (fd > 0) + close(fd); goto out; } w->len = st.st_size;