Blame SOURCES/nfs-utils-2.3.3-covscan-resource-leaks.patch

d4362b
diff -up nfs-utils-2.3.3/configure.ac.orig nfs-utils-2.3.3/configure.ac
d4362b
--- nfs-utils-2.3.3/configure.ac.orig	2019-09-18 10:57:14.190810677 -0400
d4362b
+++ nfs-utils-2.3.3/configure.ac	2019-09-18 10:57:56.715567641 -0400
d4362b
@@ -561,6 +561,7 @@ my_am_cflags="\
d4362b
  -Werror=parentheses \
d4362b
  -Werror=aggregate-return \
d4362b
  -Werror=unused-result \
d4362b
+ -Wno-cast-function-type \
d4362b
  -fno-strict-aliasing \
d4362b
 "
d4362b
 
d4362b
diff -up nfs-utils-2.3.3/support/junction/path.c.orig nfs-utils-2.3.3/support/junction/path.c
d4362b
--- nfs-utils-2.3.3/support/junction/path.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/support/junction/path.c	2019-09-18 10:57:56.715567641 -0400
d4362b
@@ -163,8 +163,10 @@ nsdb_count_components(const char *pathna
d4362b
 			break;
d4362b
 		next = strchrnul(component, '/');
d4362b
 		tmp = (size_t)(next - component);
d4362b
-		if (tmp > 255)
d4362b
+		if (tmp > 255) {
d4362b
+			free(start);
d4362b
 			return false;
d4362b
+		}
d4362b
 		length += XDR_UINT_BYTES + (nsdb_quadlen(tmp) << 2);
d4362b
 		count++;
d4362b
 
d4362b
@@ -328,11 +330,13 @@ nsdb_posix_to_path_array(const char *pat
d4362b
 		length = (size_t)(next - component);
d4362b
 		if (length > 255) {
d4362b
 			nsdb_free_string_array(result);
d4362b
+			free(normalized);
d4362b
 			return FEDFS_ERR_SVRFAULT;
d4362b
 		}
d4362b
 
d4362b
 		result[i] = strndup(component, length);
d4362b
 		if (result[i] == NULL) {
d4362b
+			free(normalized);
d4362b
 			nsdb_free_string_array(result);
d4362b
 			return FEDFS_ERR_SVRFAULT;
d4362b
 		}
d4362b
diff -up nfs-utils-2.3.3/support/nfs/exports.c.orig nfs-utils-2.3.3/support/nfs/exports.c
d4362b
--- nfs-utils-2.3.3/support/nfs/exports.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/support/nfs/exports.c	2019-09-18 10:57:56.715567641 -0400
d4362b
@@ -714,6 +714,7 @@ parsesquash(char *list, int **idp, int *
d4362b
 		}
d4362b
 		if (id0 == -1 || id1 == -1) {
d4362b
 			syntaxerr("uid/gid -1 not permitted");
d4362b
+			xfree(id);
d4362b
 			return -1;
d4362b
 		}
d4362b
 		if ((len % 8) == 0)
d4362b
@@ -724,6 +725,7 @@ parsesquash(char *list, int **idp, int *
d4362b
 			break;
d4362b
 		if (*cp != ',') {
d4362b
 			syntaxerr("bad uid/gid list");
d4362b
+			xfree(id);
d4362b
 			return -1;
d4362b
 		}
d4362b
 		cp++;
d4362b
diff -up nfs-utils-2.3.3/support/nfsidmap/libnfsidmap.c.orig nfs-utils-2.3.3/support/nfsidmap/libnfsidmap.c
d4362b
--- nfs-utils-2.3.3/support/nfsidmap/libnfsidmap.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/support/nfsidmap/libnfsidmap.c	2019-09-18 10:57:56.716567635 -0400
d4362b
@@ -406,8 +406,10 @@ int nfs4_init_name_mapping(char *conffil
d4362b
 	nfs4_methods = conf_get_list("Translation", "Method");
d4362b
 	if (nfs4_methods) {
d4362b
 		IDMAP_LOG(1, ("libnfsidmap: processing 'Method' list"));
d4362b
-		if (load_plugins(nfs4_methods, &nfs4_plugins) == -1)
d4362b
+		if (load_plugins(nfs4_methods, &nfs4_plugins) == -1) {
d4362b
+			conf_free_list(nfs4_methods);
d4362b
 			return -ENOENT;
d4362b
+		}
d4362b
 	} else {
d4362b
 		struct conf_list list;
d4362b
 		struct conf_list_node node;
d4362b
@@ -475,11 +477,15 @@ out:
d4362b
 	if (ret) {
d4362b
 		if (nfs4_plugins)
d4362b
 			unload_plugins(nfs4_plugins);
d4362b
-		if (gss_plugins)
d4362b
+		if (gss_plugins) {
d4362b
 			unload_plugins(gss_plugins);
d4362b
+		}
d4362b
 		nfs4_plugins = gss_plugins = NULL;
d4362b
 	}
d4362b
 
d4362b
+	if (gss_methods)
d4362b
+		conf_free_list(gss_methods);
d4362b
+
d4362b
 	return ret ? -ENOENT: 0;
d4362b
 }
d4362b
 
d4362b
diff -up nfs-utils-2.3.3/support/nfsidmap/static.c.orig nfs-utils-2.3.3/support/nfsidmap/static.c
d4362b
--- nfs-utils-2.3.3/support/nfsidmap/static.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/support/nfsidmap/static.c	2019-09-18 10:57:56.716567635 -0400
d4362b
@@ -347,6 +347,7 @@ static int static_init(void) {
d4362b
 			warnx("static_init: calloc (1, %lu) failed",
d4362b
 				(unsigned long)sizeof *unode);
d4362b
 			free(pw);
d4362b
+			conf_free_list(princ_list);
d4362b
 			return -ENOMEM;
d4362b
 		}
d4362b
 		unode->uid = pw->pw_uid;
d4362b
@@ -355,6 +356,9 @@ static int static_init(void) {
d4362b
 		unode->localname = conf_get_str("Static", cln->field);
d4362b
 		if (!unode->localname) {
d4362b
 			free(pw);
d4362b
+			free(unode->principal);
d4362b
+			free(unode);
d4362b
+			conf_free_list(princ_list);
d4362b
 			return -ENOENT;
d4362b
 		}
d4362b
 
d4362b
@@ -379,6 +383,7 @@ static int static_init(void) {
d4362b
 			warnx("static_init: calloc (1, %lu) failed",
d4362b
 				(unsigned long)sizeof *gnode);
d4362b
 			free(gr);
d4362b
+			conf_free_list(princ_list);
d4362b
 			return -ENOMEM;
d4362b
 		}
d4362b
 		gnode->gid = gr->gr_gid;
d4362b
@@ -387,6 +392,9 @@ static int static_init(void) {
d4362b
 		gnode->localgroup = conf_get_str("Static", cln->field);
d4362b
 		if (!gnode->localgroup) {
d4362b
 			free(gr);
d4362b
+			free(gnode->principal);
d4362b
+			free(gnode);
d4362b
+			conf_free_list(princ_list);
d4362b
 			return -ENOENT;
d4362b
 		}
d4362b
 
d4362b
@@ -394,6 +402,8 @@ static int static_init(void) {
d4362b
 
d4362b
 		LIST_INSERT_HEAD (&gid_mappings[gid_hash(gnode->gid)], gnode, link);
d4362b
 	}
d4362b
+	
d4362b
+	conf_free_list(princ_list);
d4362b
 	return 0;
d4362b
 }
d4362b
 
d4362b
diff -up nfs-utils-2.3.3/support/nfs/mydaemon.c.orig nfs-utils-2.3.3/support/nfs/mydaemon.c
d4362b
--- nfs-utils-2.3.3/support/nfs/mydaemon.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/support/nfs/mydaemon.c	2019-09-18 10:57:56.716567635 -0400
d4362b
@@ -123,6 +123,7 @@ daemon_init(bool fg)
d4362b
 	dup2(tempfd, 0);
d4362b
 	dup2(tempfd, 1);
d4362b
 	dup2(tempfd, 2);
d4362b
+	close(tempfd);
d4362b
 	closelog();
d4362b
 	dup2(pipefds[1], 3);
d4362b
 	pipefds[1] = 3;
d4362b
diff -up nfs-utils-2.3.3/support/nfs/rpcmisc.c.orig nfs-utils-2.3.3/support/nfs/rpcmisc.c
d4362b
--- nfs-utils-2.3.3/support/nfs/rpcmisc.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/support/nfs/rpcmisc.c	2019-09-18 10:57:56.716567635 -0400
d4362b
@@ -102,6 +102,7 @@ makesock(int port, int proto)
d4362b
 	if (bind(sock, (struct sockaddr *) &sin, sizeof(sin)) == -1) {
d4362b
 		xlog(L_FATAL, "Could not bind name to socket: %s",
d4362b
 					strerror(errno));
d4362b
+		close(sock);
d4362b
 		return -1;
d4362b
 	}
d4362b
 
d4362b
diff -up nfs-utils-2.3.3/support/nfs/svc_socket.c.orig nfs-utils-2.3.3/support/nfs/svc_socket.c
d4362b
--- nfs-utils-2.3.3/support/nfs/svc_socket.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/support/nfs/svc_socket.c	2019-09-18 10:57:56.717567629 -0400
d4362b
@@ -134,6 +134,7 @@ svc_socket (u_long number, int type, int
d4362b
       if (ret < 0)
d4362b
 	{
d4362b
 	  xlog(L_ERROR, "svc_socket: socket reuse problem: %m");
d4362b
+      (void) __close(sock);
d4362b
 	  return ret;
d4362b
 	}
d4362b
     }
d4362b
diff -up nfs-utils-2.3.3/support/nfs/xcommon.c.orig nfs-utils-2.3.3/support/nfs/xcommon.c
d4362b
--- nfs-utils-2.3.3/support/nfs/xcommon.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/support/nfs/xcommon.c	2019-09-18 10:57:56.717567629 -0400
d4362b
@@ -53,14 +53,17 @@ char *
d4362b
 xstrconcat3 (const char *s, const char *t, const char *u) {
d4362b
      char *res;
d4362b
 
d4362b
-     if (!s) s = "";
d4362b
+     int dofree = 1;
d4362b
+
d4362b
+     if (!s) s = "", dofree=0;
d4362b
      if (!t) t = "";
d4362b
      if (!u) u = "";
d4362b
      res = xmalloc(strlen(s) + strlen(t) + strlen(u) + 1);
d4362b
      strcpy(res, s);
d4362b
      strcat(res, t);
d4362b
      strcat(res, u);
d4362b
-     free((void *) s);
d4362b
+     if (dofree)
d4362b
+         free((void *) s);
d4362b
      return res;
d4362b
 }
d4362b
 
d4362b
@@ -69,7 +72,9 @@ char *
d4362b
 xstrconcat4 (const char *s, const char *t, const char *u, const char *v) {
d4362b
      char *res;
d4362b
 
d4362b
-     if (!s) s = "";
d4362b
+     int dofree = 1;
d4362b
+
d4362b
+     if (!s) s = "", dofree=0;
d4362b
      if (!t) t = "";
d4362b
      if (!u) u = "";
d4362b
      if (!v) v = "";
d4362b
@@ -78,7 +83,8 @@ xstrconcat4 (const char *s, const char *
d4362b
      strcat(res, t);
d4362b
      strcat(res, u);
d4362b
      strcat(res, v);
d4362b
-     free((void *) s);
d4362b
+     if (dofree)
d4362b
+         free((void *) s);
d4362b
      return res;
d4362b
 }
d4362b
 
d4362b
diff -up nfs-utils-2.3.3/support/nfs/xlog.c.orig nfs-utils-2.3.3/support/nfs/xlog.c
d4362b
--- nfs-utils-2.3.3/support/nfs/xlog.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/support/nfs/xlog.c	2019-09-18 10:57:56.717567629 -0400
d4362b
@@ -135,10 +135,14 @@ xlog_from_conffile(char *service)
d4362b
 	struct conf_list_node *n;
d4362b
 
d4362b
 	kinds = conf_get_list(service, "debug");
d4362b
-	if (!kinds || !kinds->cnt)
d4362b
+	if (!kinds || !kinds->cnt) {
d4362b
+		free(kinds);
d4362b
 		return;
d4362b
+	}
d4362b
 	TAILQ_FOREACH(n, &(kinds->fields), link)
d4362b
 		xlog_sconfig(n->field, 1);
d4362b
+
d4362b
+	conf_free_list(kinds);
d4362b
 }
d4362b
 
d4362b
 int
d4362b
diff -up nfs-utils-2.3.3/support/nsm/file.c.orig nfs-utils-2.3.3/support/nsm/file.c
d4362b
--- nfs-utils-2.3.3/support/nsm/file.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/support/nsm/file.c	2019-09-18 10:57:56.717567629 -0400
d4362b
@@ -533,6 +533,7 @@ nsm_update_kernel_state(const int state)
d4362b
 	len = snprintf(buf, sizeof(buf), "%d", state);
d4362b
 	if (error_check(len, sizeof(buf))) {
d4362b
 		xlog_warn("Failed to form NSM state number string");
d4362b
+		close(fd);
d4362b
 		return;
d4362b
 	}
d4362b
 
d4362b
diff -up nfs-utils-2.3.3/systemd/rpc-pipefs-generator.c.orig nfs-utils-2.3.3/systemd/rpc-pipefs-generator.c
d4362b
--- nfs-utils-2.3.3/systemd/rpc-pipefs-generator.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/systemd/rpc-pipefs-generator.c	2019-09-18 10:57:56.717567629 -0400
d4362b
@@ -69,12 +69,16 @@ int generate_target(char *pipefs_path, c
d4362b
 		return 1;
d4362b
 
d4362b
 	ret = generate_mount_unit(pipefs_path, pipefs_unit, dirname);
d4362b
-	if (ret)
d4362b
+	if (ret) {
d4362b
+		free(pipefs_unit);
d4362b
 		return ret;
d4362b
+	}
d4362b
 
d4362b
 	path = malloc(strlen(dirname) + 1 + sizeof(filebase));
d4362b
-	if (!path)
d4362b
+	if (!path) {
d4362b
+		free(pipefs_unit);
d4362b
 		return 2;
d4362b
+	}
d4362b
 	sprintf(path, "%s", dirname);
d4362b
 	mkdir(path, 0755);
d4362b
 	strcat(path, filebase);
d4362b
@@ -82,6 +86,7 @@ int generate_target(char *pipefs_path, c
d4362b
 	if (!f)
d4362b
 	{
d4362b
 		free(path);
d4362b
+		free(pipefs_unit);
d4362b
 		return 1;
d4362b
 	}
d4362b
 
d4362b
@@ -90,6 +95,7 @@ int generate_target(char *pipefs_path, c
d4362b
 	fprintf(f, "After=%s\n", pipefs_unit);
d4362b
 	fclose(f);
d4362b
 	free(path);
d4362b
+	free(pipefs_unit);
d4362b
 
d4362b
 	return 0;
d4362b
 }
d4362b
diff -up nfs-utils-2.3.3/utils/blkmapd/device-discovery.c.orig nfs-utils-2.3.3/utils/blkmapd/device-discovery.c
d4362b
--- nfs-utils-2.3.3/utils/blkmapd/device-discovery.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/utils/blkmapd/device-discovery.c	2019-09-18 10:58:54.444237714 -0400
d4362b
@@ -186,8 +186,11 @@ static void bl_add_disk(char *filepath)
d4362b
 		}
d4362b
 	}
d4362b
 
d4362b
-	if (disk && diskpath)
d4362b
+	if (disk && diskpath) {
d4362b
+		if (serial)
d4362b
+			free(serial);
d4362b
 		return;
d4362b
+	}
d4362b
 
d4362b
 	/* add path */
d4362b
 	path = malloc(sizeof(struct bl_disk_path));
d4362b
@@ -223,6 +226,8 @@ static void bl_add_disk(char *filepath)
d4362b
 			disk->size = size;
d4362b
 			disk->valid_path = path;
d4362b
 		}
d4362b
+		if (serial)
d4362b
+			free(serial);
d4362b
 	}
d4362b
 	return;
d4362b
 
d4362b
@@ -232,6 +237,9 @@ static void bl_add_disk(char *filepath)
d4362b
 			free(path->full_path);
d4362b
 		free(path);
d4362b
 	}
d4362b
+	if (serial)
d4362b
+		free(serial);
d4362b
+
d4362b
 	return;
d4362b
 }
d4362b
 
d4362b
@@ -375,7 +383,12 @@ static void bl_rpcpipe_cb(void)
d4362b
 			if (event->mask & IN_CREATE) {
d4362b
 				BL_LOG_WARNING("nfs pipe dir created\n");
d4362b
 				bl_watch_dir(nfspipe_dir, &nfs_pipedir_wfd);
d4362b
+				if (bl_pipe_fd >= 0)
d4362b
+					close(bl_pipe_fd);
d4362b
 				bl_pipe_fd = open(bl_pipe_file, O_RDWR);
d4362b
+				if (bl_pipe_fd < 0)
d4362b
+					BL_LOG_ERR("open %s failed: %s\n",
d4362b
+						event->name, strerror(errno));
d4362b
 			} else if (event->mask & IN_DELETE) {
d4362b
 				BL_LOG_WARNING("nfs pipe dir deleted\n");
d4362b
 				inotify_rm_watch(bl_watch_fd, nfs_pipedir_wfd);
d4362b
@@ -388,6 +401,8 @@ static void bl_rpcpipe_cb(void)
d4362b
 				continue;
d4362b
 			if (event->mask & IN_CREATE) {
d4362b
 				BL_LOG_WARNING("blocklayout pipe file created\n");
d4362b
+				if (bl_pipe_fd >= 0)
d4362b
+					close(bl_pipe_fd);
d4362b
 				bl_pipe_fd = open(bl_pipe_file, O_RDWR);
d4362b
 				if (bl_pipe_fd < 0)
d4362b
 					BL_LOG_ERR("open %s failed: %s\n",
d4362b
diff -up nfs-utils-2.3.3/utils/gssd/krb5_util.c.orig nfs-utils-2.3.3/utils/gssd/krb5_util.c
d4362b
--- nfs-utils-2.3.3/utils/gssd/krb5_util.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/utils/gssd/krb5_util.c	2019-09-18 10:57:56.718567624 -0400
d4362b
@@ -698,6 +698,8 @@ gssd_search_krb5_keytab(krb5_context con
d4362b
 				 "we failed to unparse principal name: %s\n",
d4362b
 				 k5err);
d4362b
 			k5_free_kt_entry(context, kte);
d4362b
+			free(k5err);
d4362b
+			k5err = NULL;
d4362b
 			continue;
d4362b
 		}
d4362b
 		printerr(4, "Processing keytab entry for principal '%s'\n",
d4362b
@@ -899,6 +901,8 @@ find_keytab_entry(krb5_context context,
d4362b
 				k5err = gssd_k5_err_msg(context, code);
d4362b
 				printerr(1, "%s while building principal for '%s'\n",
d4362b
 					 k5err, spn);
d4362b
+				free(k5err);
d4362b
+				k5err = NULL;
d4362b
 				continue;
d4362b
 			}
d4362b
 			code = krb5_kt_get_entry(context, kt, princ, 0, 0, kte);
d4362b
@@ -1168,7 +1172,8 @@ gssd_get_krb5_machine_cred_list(char ***
d4362b
 		*list = l;
d4362b
 		retval = 0;
d4362b
 		goto out;
d4362b
-	}
d4362b
+	} else
d4362b
+		free((void *)l);
d4362b
   out:
d4362b
 	return retval;
d4362b
 }
d4362b
@@ -1216,6 +1221,8 @@ gssd_destroy_krb5_machine_creds(void)
d4362b
 			printerr(0, "WARNING: %s while resolving credential "
d4362b
 				    "cache '%s' for destruction\n", k5err,
d4362b
 				    ple->ccname);
d4362b
+			free(k5err);
d4362b
+			k5err = NULL;
d4362b
 			continue;
d4362b
 		}
d4362b
 
d4362b
diff -up nfs-utils-2.3.3/utils/mount/configfile.c.orig nfs-utils-2.3.3/utils/mount/configfile.c
d4362b
--- nfs-utils-2.3.3/utils/mount/configfile.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/utils/mount/configfile.c	2019-09-18 10:57:56.718567624 -0400
d4362b
@@ -404,7 +404,7 @@ char *conf_get_mntopts(char *spec, char
d4362b
 
d4362b
 	/* list_size + optlen + ',' + '\0' */
d4362b
 	config_opts = calloc(1, (list_size+optlen+2));
d4362b
-	if (server == NULL) {
d4362b
+	if (config_opts == NULL) {
d4362b
 		xlog_warn("conf_get_mountops: Unable calloc memory for config_opts"); 
d4362b
 		free_all();
d4362b
 		return mount_opts;
d4362b
diff -up nfs-utils-2.3.3/utils/mountd/cache.c.orig nfs-utils-2.3.3/utils/mountd/cache.c
d4362b
--- nfs-utils-2.3.3/utils/mountd/cache.c.orig	2019-09-18 10:57:14.190810677 -0400
d4362b
+++ nfs-utils-2.3.3/utils/mountd/cache.c	2019-09-18 10:57:56.718567624 -0400
d4362b
@@ -1240,7 +1240,7 @@ static struct exportent *lookup_junction
d4362b
 		goto out;
d4362b
 	}
d4362b
 	status = nfs_get_basic_junction(pathname, &locations);
d4362b
-	switch (status) {
d4362b
+	if (status) {
d4362b
 		xlog(L_WARNING, "Dangling junction %s: %s",
d4362b
 			pathname, strerror(status));
d4362b
 		goto out;
d4362b
@@ -1248,10 +1248,11 @@ static struct exportent *lookup_junction
d4362b
 
d4362b
 	parent = lookup_parent_export(dom, pathname, ai);
d4362b
 	if (parent == NULL)
d4362b
-		goto out;
d4362b
+		goto free_locations;
d4362b
 
d4362b
 	exp = locations_to_export(locations, pathname, parent);
d4362b
 
d4362b
+free_locations:
d4362b
 	nfs_free_locations(locations->ns_list);
d4362b
 	free(locations);
d4362b
 
d4362b
diff -up nfs-utils-2.3.3/utils/mountd/fsloc.c.orig nfs-utils-2.3.3/utils/mountd/fsloc.c
d4362b
--- nfs-utils-2.3.3/utils/mountd/fsloc.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/utils/mountd/fsloc.c	2019-09-18 10:57:56.719567618 -0400
d4362b
@@ -102,6 +102,7 @@ static struct servers *parse_list(char *
d4362b
 		cp = strchr(list[i], '@');
d4362b
 		if ((!cp) || list[i][0] != '/') {
d4362b
 			xlog(L_WARNING, "invalid entry '%s'", list[i]);
d4362b
+			free(mp);
d4362b
 			continue; /* XXX Need better error handling */
d4362b
 		}
d4362b
 		res->h_mp[i] = mp;
d4362b
diff -up nfs-utils-2.3.3/utils/mount/nfsmount.c.orig nfs-utils-2.3.3/utils/mount/nfsmount.c
d4362b
--- nfs-utils-2.3.3/utils/mount/nfsmount.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/utils/mount/nfsmount.c	2019-09-18 10:57:56.730567555 -0400
d4362b
@@ -452,6 +452,7 @@ parse_options(char *old_opts, struct nfs
d4362b
 	nfs_error(_("%s: Bad nfs mount parameter: %s\n"), progname, opt);
d4362b
  out_bad:
d4362b
 	free(tmp_opts);
d4362b
+	free(mounthost);
d4362b
 	return 0;
d4362b
 }
d4362b
 
d4362b
diff -up nfs-utils-2.3.3/utils/mount/stropts.c.orig nfs-utils-2.3.3/utils/mount/stropts.c
d4362b
--- nfs-utils-2.3.3/utils/mount/stropts.c.orig	2019-09-18 10:57:14.183810717 -0400
d4362b
+++ nfs-utils-2.3.3/utils/mount/stropts.c	2019-09-18 10:57:56.730567555 -0400
d4362b
@@ -982,8 +982,11 @@ static int nfs_try_mount(struct nfsmount
d4362b
 		}
d4362b
 
d4362b
 		if (!nfs_append_addr_option(address->ai_addr,
d4362b
-					    address->ai_addrlen, mi->options))
d4362b
+					    address->ai_addrlen, mi->options)) {
d4362b
+			freeaddrinfo(address);
d4362b
+			errno = ENOMEM;
d4362b
 			return 0;
d4362b
+		}
d4362b
 		mi->address = address;
d4362b
 	}
d4362b
 
d4362b
diff -up nfs-utils-2.3.3/utils/nfsdcltrack/sqlite.c.orig nfs-utils-2.3.3/utils/nfsdcltrack/sqlite.c
d4362b
--- nfs-utils-2.3.3/utils/nfsdcltrack/sqlite.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/utils/nfsdcltrack/sqlite.c	2019-09-18 10:57:56.731567549 -0400
d4362b
@@ -215,6 +215,8 @@ sqlite_maindb_init_v2(void)
d4362b
 				&err;;
d4362b
 	if (ret != SQLITE_OK) {
d4362b
 		xlog(L_ERROR, "Unable to begin transaction: %s", err);
d4362b
+		if (err)
d4362b
+			sqlite3_free(err);
d4362b
 		return ret;
d4362b
 	}
d4362b
 
d4362b
diff -up nfs-utils-2.3.3/support/nfsidmap/libnfsidmap.c.orig nfs-utils-2.3.3/support/nfsidmap/libnfsidmap.c
d4362b
--- nfs-utils-2.3.3/support/nfsidmap/libnfsidmap.c.orig	2019-11-11 08:49:06.044870974 -0500
d4362b
+++ nfs-utils-2.3.3/support/nfsidmap/libnfsidmap.c	2019-11-11 09:19:10.391896845 -0500
d4362b
@@ -486,6 +486,9 @@ out:
d4362b
 	if (gss_methods)
d4362b
 		conf_free_list(gss_methods);
d4362b
 
d4362b
+	if (nfs4_methods)
d4362b
+		conf_free_list(nfs4_methods);
d4362b
+
d4362b
 	return ret ? -ENOENT: 0;
d4362b
 }
d4362b
 
d4362b
diff -up nfs-utils-2.3.3/utils/gssd/krb5_util.c.orig nfs-utils-2.3.3/utils/gssd/krb5_util.c
d4362b
--- nfs-utils-2.3.3/utils/gssd/krb5_util.c.orig	2019-11-11 08:49:06.045870979 -0500
d4362b
+++ nfs-utils-2.3.3/utils/gssd/krb5_util.c	2019-11-11 09:19:10.393896856 -0500
d4362b
@@ -911,6 +911,8 @@ find_keytab_entry(krb5_context context,
d4362b
 				k5err = gssd_k5_err_msg(context, code);
d4362b
 				printerr(3, "%s while getting keytab entry for '%s'\n",
d4362b
 					 k5err, spn);
d4362b
+				free(k5err);
d4362b
+				k5err = NULL;
d4362b
 				/*
d4362b
 				 * We tried the active directory machine account
d4362b
 				 * with the hostname part as-is and failed...
d4362b
@@ -1013,6 +1015,8 @@ query_krb5_ccache(const char* cred_cache
d4362b
 	char *str = NULL;
d4362b
 	char *princstring;
d4362b
 
d4362b
+	*ret_princname = *ret_realm = NULL;
d4362b
+
d4362b
 	ret = krb5_init_context(&context);
d4362b
 	if (ret) 
d4362b
 		return 0;
d4362b
@@ -1047,7 +1051,7 @@ err_princ:
d4362b
 	krb5_cc_close(context, ccache);
d4362b
 err_cache:
d4362b
 	krb5_free_context(context);
d4362b
-	return found;
d4362b
+	return (*ret_princname && *ret_realm);
d4362b
 }
d4362b
 
d4362b
 /*==========================*/
d4362b
@@ -1230,6 +1234,8 @@ gssd_destroy_krb5_machine_creds(void)
d4362b
 			k5err = gssd_k5_err_msg(context, code);
d4362b
 			printerr(0, "WARNING: %s while destroying credential "
d4362b
 				    "cache '%s'\n", k5err, ple->ccname);
d4362b
+			free(k5err);
d4362b
+			k5err = NULL;
d4362b
 		}
d4362b
 	}
d4362b
 	krb5_free_context(context);
d4362b
diff -up nfs-utils-2.3.3/utils/idmapd/idmapd.c.orig nfs-utils-2.3.3/utils/idmapd/idmapd.c
d4362b
--- nfs-utils-2.3.3/utils/idmapd/idmapd.c.orig	2019-11-11 08:49:06.029870889 -0500
d4362b
+++ nfs-utils-2.3.3/utils/idmapd/idmapd.c	2019-11-11 09:19:10.393896856 -0500
d4362b
@@ -517,14 +517,16 @@ static void
d4362b
 clntscancb(int UNUSED(fd), short UNUSED(which), void *data)
d4362b
 {
d4362b
 	struct idmap_clientq *icq = data;
d4362b
-	struct idmap_client *ic;
d4362b
+	struct idmap_client *ic, *ic_next;
d4362b
 
d4362b
-	TAILQ_FOREACH(ic, icq, ic_next)
d4362b
+	for (ic = TAILQ_FIRST(icq); ic != NULL; ic = ic_next) { 
d4362b
+		ic_next = TAILQ_NEXT(ic, ic_next);
d4362b
 		if (ic->ic_fd == -1 && nfsopen(ic) == -1) {
d4362b
 			close(ic->ic_dirfd);
d4362b
 			TAILQ_REMOVE(icq, ic, ic_next);
d4362b
 			free(ic);
d4362b
 		}
d4362b
+	}
d4362b
 }
d4362b
 
d4362b
 static void
d4362b
diff -up nfs-utils-2.3.3/utils/statd/monitor.c.orig nfs-utils-2.3.3/utils/statd/monitor.c
d4362b
--- nfs-utils-2.3.3/utils/statd/monitor.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/utils/statd/monitor.c	2019-11-11 09:19:10.393896856 -0500
d4362b
@@ -66,7 +66,7 @@ sm_mon_1_svc(struct mon *argp, struct sv
d4362b
 			*my_name  = argp->mon_id.my_id.my_name;
d4362b
 	struct my_id	*id = &argp->mon_id.my_id;
d4362b
 	char		*cp;
d4362b
-	notify_list	*clnt;
d4362b
+	notify_list	*clnt = NULL;
d4362b
 	struct sockaddr_in my_addr = {
d4362b
 		.sin_family		= AF_INET,
d4362b
 		.sin_addr.s_addr	= htonl(INADDR_LOOPBACK),
d4362b
@@ -177,6 +177,7 @@ sm_mon_1_svc(struct mon *argp, struct sv
d4362b
 	 * We're committed...ignoring errors.  Let's hope that a malloc()
d4362b
 	 * doesn't fail.  (I should probably fix this assumption.)
d4362b
 	 */
d4362b
+	clnt = NULL;
d4362b
 	if (!existing && !(clnt = nlist_new(my_name, mon_name, 0))) {
d4362b
 		free(dnsname);
d4362b
 		xlog_warn("out of memory");
d4362b
@@ -223,6 +224,7 @@ sm_mon_1_svc(struct mon *argp, struct sv
d4362b
 
d4362b
 failure:
d4362b
 	xlog_warn("STAT_FAIL to %s for SM_MON of %s", my_name, mon_name);
d4362b
+	free(clnt);
d4362b
 	return (&result);
d4362b
 }
d4362b
 
d4362b
@@ -242,6 +244,7 @@ load_one_host(const char *hostname,
d4362b
 	clnt->dns_name = strdup(hostname);
d4362b
 	if (clnt->dns_name == NULL) {
d4362b
 		nlist_free(NULL, clnt);
d4362b
+		free(clnt);
d4362b
 		return 0;
d4362b
 	}
d4362b
 
d4362b
diff -up nfs-utils-2.3.3/utils/statd/notlist.c.orig nfs-utils-2.3.3/utils/statd/notlist.c
d4362b
--- nfs-utils-2.3.3/utils/statd/notlist.c.orig	2018-09-06 14:09:08.000000000 -0400
d4362b
+++ nfs-utils-2.3.3/utils/statd/notlist.c	2019-11-11 09:19:10.394896861 -0500
d4362b
@@ -210,7 +210,6 @@ nlist_free(notify_list **head, notify_li
d4362b
 	if (NL_MON_NAME(entry))
d4362b
 		free(NL_MON_NAME(entry));
d4362b
 	free(entry->dns_name);
d4362b
-	free(entry);
d4362b
 }
d4362b
 
d4362b
 /* 
d4362b
@@ -219,8 +218,14 @@ nlist_free(notify_list **head, notify_li
d4362b
 void 
d4362b
 nlist_kill(notify_list **head)
d4362b
 {
d4362b
-	while (*head)
d4362b
+	notify_list *next;
d4362b
+
d4362b
+	while (*head) {
d4362b
+		next = (*head)->next;
d4362b
 		nlist_free(head, *head);
d4362b
+		free(*head);
d4362b
+		*head = next;
d4362b
+	}
d4362b
 }
d4362b
 
d4362b
 /*