From 4996a229f3d09cbb6ed3b9dcdf1d527f36803919 Mon Sep 17 00:00:00 2001 From: Sunny Kumar Date: Mon, 13 Aug 2018 12:18:51 +0530 Subject: 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 --- libglusterfs/src/common-utils.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index e547ad929af..4c98e705e5e 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; } -- cgit