From e994fbc825b0ce48bbe0c23d034e821502359912 Mon Sep 17 00:00:00 2001 From: Girjesh Rajoria Date: Sat, 23 Sep 2017 02:28:34 +0530 Subject: libglusterfs: Coverity Issue NEGATIVE_RETURNS Issue: Event negative_return_fn: Function "dup(handle->fd)" returns a negative number. Event negative_returns: "dup(handle->fd)" is passed to a parameter that cannot be negative. With this change value of dup(handle->fd) is stored in duped_fd & if condition checks the value of duped_fd is non-negative. Change-Id: I563d717108016d740ffa64fbe0929eb1e08c8f33 BUG: 789278 Signed-off-by: Girjesh Rajoria --- libglusterfs/src/store.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/store.c b/libglusterfs/src/store.c index e805f20bb4c..d22027b32c7 100644 --- a/libglusterfs/src/store.c +++ b/libglusterfs/src/store.c @@ -257,17 +257,21 @@ gf_store_retrieve_value (gf_store_handle_t *handle, char *key, char **value) "Unable to open file %s", handle->path); goto out; } - if (!handle->read) - handle->read = fdopen (dup(handle->fd), "r"); - else - fseek (handle->read, 0, SEEK_SET); - if (!handle->read) { - gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, - "Unable to open file %s", handle->path); - goto out; + int duped_fd = dup(handle->fd); + + if (duped_fd >= 0) + handle->read = fdopen (duped_fd, "r"); + if (!handle->read) { + if (duped_fd != -1) + sys_close (duped_fd); + gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, + "Unable to open file %s", handle->path); + goto out; + } + } else { + fseek (handle->read, 0, SEEK_SET); } - ret = sys_fstat (handle->fd, &st); if (ret < 0) { gf_msg ("", GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, -- cgit