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 <sharpd@nvidia.com>
This commit is contained in:
Donald Sharp 2023-04-21 09:12:08 -04:00
parent 6f99cfcd89
commit a7209c2dbc

View File

@ -1140,7 +1140,8 @@ static PyObject *elffile_load(PyTypeObject *type, PyObject *args,
fd = open(filename, O_RDONLY | O_NOCTTY); fd = open(filename, O_RDONLY | O_NOCTTY);
if (fd < 0 || fstat(fd, &st)) { if (fd < 0 || fstat(fd, &st)) {
PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename); PyErr_SetFromErrnoWithFilename(PyExc_OSError, filename);
close(fd); if (fd > 0)
close(fd);
goto out; goto out;
} }
w->len = st.st_size; w->len = st.st_size;