diff options
author | Sunny Kumar <sunkumar@redhat.com> | 2018-08-13 12:18:51 +0530 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-08-31 01:29:06 +0000 |
commit | 4996a229f3d09cbb6ed3b9dcdf1d527f36803919 (patch) | |
tree | 0d8416d86e039858f6d9e81a1e3785a4442f622f | |
parent | 25c405ac688787ea3f03ca4d427f2b00544dbbd0 (diff) | |
download | glusterfs-4996a229f3d09cbb6ed3b9dcdf1d527f36803919.tar.gz glusterfs-4996a229f3d09cbb6ed3b9dcdf1d527f36803919.tar.xz glusterfs-4996a229f3d09cbb6ed3b9dcdf1d527f36803919.zip |
libglusterfs : fix coverity issues in common-utils.c
Fixes CID 1351691, 1351678, 1274192, 1274117, 1124845.
Change-Id: I65805524de85fb2186260288641390458a719499
updates: bz#789278
Signed-off-by: Sunny Kumar <sunkumar@redhat.com>
-rw-r--r-- | libglusterfs/src/common-utils.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index e547ad929a..4c98e705e5 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -385,8 +385,11 @@ gf_dnscache_init (time_t ttl) { struct dnscache *cache = GF_MALLOC (sizeof (*cache), gf_common_mt_dnscache); - cache->cache_dict = NULL; - cache->ttl = ttl; + if (cache) { + cache->cache_dict = NULL; + cache->ttl = ttl; + } + return cache; } @@ -489,11 +492,12 @@ out: goto out; } entry->fqdn = fqdn; - entry->ip = gf_strdup (ip); if (!ip) { gf_dnscache_entry_deinit (entry); goto out; } + + entry->ip = gf_strdup (ip); entry->timestamp = time (NULL); entrydata = bin_to_data (entry, sizeof (*entry)); @@ -3043,6 +3047,8 @@ gf_get_reserved_ports () " getting reserved ports info", proc_file); goto out; } + + buffer[ret] = '\0'; ports_info = gf_strdup (buffer); out: @@ -3418,8 +3424,11 @@ gf_is_local_addr (char *hostname) gf_msg_debug (this->name, 0, "%s ", get_ip_from_addrinfo (res, &ip)); - found = gf_is_loopback_localhost (res->ai_addr, hostname) - || gf_interface_search (ip); + if (ip) { + found = gf_is_loopback_localhost + (res->ai_addr, hostname) || + gf_interface_search (ip); + } if (found) { GF_FREE (ip); goto out; @@ -3895,8 +3904,10 @@ gf_is_service_running (char *pidfile, int *pid) fno = fileno (file); ret = lockf (fno, F_TEST, 0); - if (ret == -1) + if (ret == -1) { running = _gf_true; + goto out; + } ret = fscanf (file, "%d", pid); if (ret <= 0) { @@ -4429,6 +4440,7 @@ recursive_rmdir (const char *delete_path) if (ret == -1) { gf_msg_debug (this->name, 0, "Failed to stat entry %s :" " %s", path, strerror (errno)); + (void) sys_closedir (dir); goto out; } |