diff options
| author | Girjesh Rajoria <grajoria@redhat.com> | 2017-09-23 02:28:34 +0530 | 
|---|---|---|
| committer | Jeff Darcy <jeff@pl.atyp.us> | 2017-09-29 12:37:26 +0000 | 
| commit | e994fbc825b0ce48bbe0c23d034e821502359912 (patch) | |
| tree | c2682e1f9b0de6cf022873cd2787edbd620f4add | |
| parent | 9af20af096a14c6297ca8f89697f2a9e4e83bd8f (diff) | |
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 <grajoria@redhat.com>
| -rw-r--r-- | libglusterfs/src/store.c | 22 | 
1 files changed, 13 insertions, 9 deletions
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,  | 
