Skip to contentSkip to conversation

Covertity Scan: Removed resources leaks

PATCH In review Steve Dickson 1 participant 21 messages May 8, 2019 – May 10, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Covertity Scan: Removed resources leaks

Red Hat is now requiring covertity scans to be run against all RHEL 8 packages.

These patches removed the majority of the resource leaks that were flagged by the scan.

Most of the leaks were in return and error paths as well as some obvious problems like checking the wrong point to be NULL.

There are still a few resources leaks and used_after_freed being flagged but I am thinking they false-positives because I just don't see the problem.

I've tested these patches for a couple days and they seem stable... but whenever free()s are added... So is risk of freeing that is still being used. Plus they will get a good workout at the upcoming Bakeathon.

Steve Dickson (19):
Removed resource leaks from junction/path.c Removed resource leaks from nfs/exports.c Removed a resource leak from nfs/mydaemon.c Removed a resource leak from nfs/rpcmisc.c Removed a resource leak from nfs/svc_socket.c Removed bad frees from nfs/xcommon.c
Removed resource leaks from nfs/xlog.c
Removed resource leaks from nfsidmap/libnfsidmap.c Removed resource leaks from nfsidmap/static.c Removed a resource leak from nsm/file.c
Removed resource leaks from systemd/rpc-pipefs-generator.c Removed resource leaks from blkmapd/device-discovery.c Removed resource leaks from gssd/krb5_util.c Removed a resource leak from mount/configfile.c Removed a resource leak from mount/nfsmount.c Removed a resource leak from mount/stropts.c Removed resource leaks from mountd/cache.c Removed a resource leak from mountd/fsloc.c Removed a resource leak from nfsdcltrack/sqlite.c

 support/junction/path.c          |  6 +++++-
 support/nfs/exports.c            |  2 ++
 support/nfs/mydaemon.c           |  1 +
 support/nfs/rpcmisc.c            |  1 +
 support/nfs/svc_socket.c         |  1 +
 support/nfs/xcommon.c            | 14 ++++++++++----
 support/nfs/xlog.c               |  6 +++++-
 support/nfsidmap/libnfsidmap.c   | 10 ++++++++--
 support/nfsidmap/static.c        | 10 ++++++++++
 support/nsm/file.c               |  1 +
 systemd/rpc-pipefs-generator.c   | 10 ++++++++--
 utils/blkmapd/device-discovery.c | 22 +++++++++++++++++++++-
 utils/gssd/krb5_util.c           |  9 ++++++++-
 utils/mount/configfile.c         |  2 +-
 utils/mount/nfsmount.c           |  1 +
 utils/mount/stropts.c            |  5 ++++-
 utils/mountd/cache.c             |  5 +++--
 utils/mountd/fsloc.c             |  1 +
 utils/nfsdcltrack/sqlite.c       |  2 ++
 19 files changed, 93 insertions(+), 16 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/19 Removed resource leaks from junction/path.c

junction/path.c:167: leaked_storage: Variable "start" going out
of scope leaks the storage it points to.

junction/path.c:331: leaked_storage: Variable "normalized" going out
of scope leaks the storage it points to.

junction/path.c:340: leaked_storage: Variable "normalized" going out
of scope leaks the storage it points to.

---
 support/junction/path.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
support/junction/path.c +5 -1
index e74e4c4..13a1438 100644
@@ -163,8 +163,10 @@ nsdb_count_components(const char *pathname, size_t *len,
 			break;
 		next = strchrnul(component, '/');
 		tmp = (size_t)(next - component);
-		if (tmp > 255)
+		if (tmp > 255) {
+			free(start);
 			return false;
+		}
 		length += XDR_UINT_BYTES + (nsdb_quadlen(tmp) << 2);
 		count++;
 
@@ -328,11 +330,13 @@ nsdb_posix_to_path_array(const char *pathname, char ***path_array)
 		length = (size_t)(next - component);
 		if (length > 255) {
 			nsdb_free_string_array(result);
+			free(normalized);
 			return FEDFS_ERR_SVRFAULT;
 		}
 
 		result[i] = strndup(component, length);
 		if (result[i] == NULL) {
+			free(normalized);
 			nsdb_free_string_array(result);
 			return FEDFS_ERR_SVRFAULT;
 		}
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/19 Removed resource leaks from nfs/exports.c

In reply to Steve Dickson

nfs/exports.c:717: leaked_storage: Variable "id" going out
of scope leaks the storage it points to.

nfs/exports.c:727: leaked_storage: Variable "id" going out
of scope leaks the storage it points to.

---
 support/nfs/exports.c | 2 ++
 1 file changed, 2 insertions(+)
support/nfs/exports.c +2 -0
index b59d187..5f4cb95 100644
@@ -714,6 +714,7 @@ parsesquash(char *list, int **idp, int *lenp, char **ep)
 		}
 		if (id0 == -1 || id1 == -1) {
 			syntaxerr("uid/gid -1 not permitted");
+			xfree(id);
 			return -1;
 		}
 		if ((len % 8) == 0)
@@ -724,6 +725,7 @@ parsesquash(char *list, int **idp, int *lenp, char **ep)
 			break;
 		if (*cp != ',') {
 			syntaxerr("bad uid/gid list");
+			xfree(id);
 			return -1;
 		}
 		cp++;
Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/19 Removed a resource leak from nfs/mydaemon.c

In reply to Steve Dickson

nfs/mydaemon.c:130: leaked_handle: Handle variable "tempfd"
going out of scope leaks the handle.

---
 support/nfs/mydaemon.c | 1 +
 1 file changed, 1 insertion(+)
support/nfs/mydaemon.c +1 -0
index 343e80b..d1cf08d 100644
@@ -123,6 +123,7 @@ daemon_init(bool fg)
 	dup2(tempfd, 0);
 	dup2(tempfd, 1);
 	dup2(tempfd, 2);
+	close(tempfd);
 	closelog();
 	dup2(pipefds[1], 3);
 	pipefds[1] = 3;
Signature · 1 line
2.20.1
#4 lore raw

PATCH 4/19 Removed a resource leak from nfs/rpcmisc.c

In reply to Steve Dickson

nfs/rpcmisc.c:105: leaked_handle: Handle variable "sock"
going out of scope leaks the handle.

---
 support/nfs/rpcmisc.c | 1 +
 1 file changed, 1 insertion(+)
support/nfs/rpcmisc.c +1 -0
index abe89ba..d84c04f 100644
@@ -102,6 +102,7 @@ makesock(int port, int proto)
 	if (bind(sock, (struct sockaddr *) &sin, sizeof(sin)) == -1) {
 		xlog(L_FATAL, "Could not bind name to socket: %s",
 					strerror(errno));
+		close(sock);
 		return -1;
 	}
 
Signature · 1 line
2.20.1
#5 lore raw

PATCH 5/19 Removed a resource leak from nfs/svc_socket.c

In reply to Steve Dickson

nfs/svc_socket.c:137: leaked_handle: Handle variable "sock"
going out of scope leaks the handle.

---
 support/nfs/svc_socket.c | 1 +
 1 file changed, 1 insertion(+)
support/nfs/svc_socket.c +1 -0
index d56507a..5afc6aa 100644
@@ -134,6 +134,7 @@ svc_socket (u_long number, int type, int protocol, int reuse)
       if (ret < 0)
 	{
 	  xlog(L_ERROR, "svc_socket: socket reuse problem: %m");
+      (void) __close(sock);
 	  return ret;
 	}
     }
Signature · 1 line
2.20.1
#6 lore raw

PATCH 6/19 Removed bad frees from nfs/xcommon.c

In reply to Steve Dickson

nfs/xcommon.c:63: incorrect_free: "free" frees incorrect pointer "(void *)s". nfs/xcommon.c:81: incorrect_free: "free" frees incorrect pointer "(void *)s".

---
 support/nfs/xcommon.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
support/nfs/xcommon.c +10 -4
index 14e580e..3989f0b 100644
@@ -53,14 +53,17 @@ char *
 xstrconcat3 (const char *s, const char *t, const char *u) {
      char *res;
 
-     if (!s) s = "";
+     int dofree = 1;
+
+     if (!s) s = "", dofree=0;
      if (!t) t = "";
      if (!u) u = "";
      res = xmalloc(strlen(s) + strlen(t) + strlen(u) + 1);
      strcpy(res, s);
      strcat(res, t);
      strcat(res, u);
-     free((void *) s);
+     if (dofree)
+         free((void *) s);
      return res;
 }
 
@@ -69,7 +72,9 @@ char *
 xstrconcat4 (const char *s, const char *t, const char *u, const char *v) {
      char *res;
 
-     if (!s) s = "";
+     int dofree = 1;
+
+     if (!s) s = "", dofree=0;
      if (!t) t = "";
      if (!u) u = "";
      if (!v) v = "";
@@ -78,7 +83,8 @@ xstrconcat4 (const char *s, const char *t, const char *u, const char *v) {
      strcat(res, t);
      strcat(res, u);
      strcat(res, v);
-     free((void *) s);
+     if (dofree)
+         free((void *) s);
      return res;
 }
 
Signature · 1 line
2.20.1
#7 lore raw

PATCH 7/19 Removed resource leaks from nfs/xlog.c

In reply to Steve Dickson

nfs/xlog.c:139: leaked_storage: Variable "kinds" going out
of scope leaks the storage it points to.

nfs/xlog.c:142: leaked_storage: Variable "kinds" going out
of scope leaks the storage it points to.

---
 support/nfs/xlog.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
support/nfs/xlog.c +5 -1
index f75a9ab..687d862 100644
@@ -135,10 +135,14 @@ xlog_from_conffile(char *service)
 	struct conf_list_node *n;
 
 	kinds = conf_get_list(service, "debug");
-	if (!kinds || !kinds->cnt)
+	if (!kinds || !kinds->cnt) {
+		free(kinds);
 		return;
+	}
 	TAILQ_FOREACH(n, &(kinds->fields), link)
 		xlog_sconfig(n->field, 1);
+
+	conf_free_list(kinds);
 }
 
 int
Signature · 1 line
2.20.1
#8 lore raw

PATCH 8/19 Removed resource leaks from nfsidmap/libnfsidmap.c

In reply to Steve Dickson

nfsidmap/libnfsidmap.c:410: leaked_storage: Variable "nfs4_methods"
going out of scope leaks the storage it points to.

ibnfsidmap.c:483: leaked_storage: Variable "gss_methods"
going out of scope leaks the storage it points to.

---
 support/nfsidmap/libnfsidmap.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
support/nfsidmap/libnfsidmap.c +8 -2
index 35ddf01..7b8a871 100644
@@ -406,8 +406,10 @@ int nfs4_init_name_mapping(char *conffile)
 	nfs4_methods = conf_get_list("Translation", "Method");
 	if (nfs4_methods) {
 		IDMAP_LOG(1, ("libnfsidmap: processing 'Method' list"));
-		if (load_plugins(nfs4_methods, &nfs4_plugins) == -1)
+		if (load_plugins(nfs4_methods, &nfs4_plugins) == -1) {
+			conf_free_list(nfs4_methods);
 			return -ENOENT;
+		}
 	} else {
 		struct conf_list list;
 		struct conf_list_node node;
@@ -475,11 +477,15 @@ out:
 	if (ret) {
 		if (nfs4_plugins)
 			unload_plugins(nfs4_plugins);
-		if (gss_plugins)
+		if (gss_plugins) {
 			unload_plugins(gss_plugins);
+		}
 		nfs4_plugins = gss_plugins = NULL;
 	}
 
+	if (gss_methods)
+		conf_free_list(gss_methods);
+
 	return ret ? -ENOENT: 0;
 }
 
Signature · 1 line
2.20.1
#9 lore raw

PATCH 9/19 Removed resource leaks from nfsidmap/static.c

In reply to Steve Dickson

nfsidmap/static.c:350: leaked_storage: Variable "princ_list"
going out of scope leaks the storage it points to.
nfsidmap/static.c:358: leaked_storage: Variable "princ_list"
going out of scope leaks the storage it points to.
nfsidmap/static.c:360: leaked_storage: Variable "unode"
going out of scope leaks the storage it points to.
nfsidmap/static.c:382: leaked_storage: Variable "princ_list"
going out of scope leaks the storage it points to.
nfsidmap/static.c:390: leaked_storage: Variable "gnode"
going out of scope leaks the storage it points to.

---
 support/nfsidmap/static.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
support/nfsidmap/static.c +10 -0
index f7b8a67..8ac4a39 100644
@@ -347,6 +347,7 @@ static int static_init(void) {
 			warnx("static_init: calloc (1, %lu) failed",
 				(unsigned long)sizeof *unode);
 			free(pw);
+			conf_free_list(princ_list);
 			return -ENOMEM;
 		}
 		unode->uid = pw->pw_uid;
@@ -355,6 +356,9 @@ static int static_init(void) {
 		unode->localname = conf_get_str("Static", cln->field);
 		if (!unode->localname) {
 			free(pw);
+			free(unode->principal);
+			free(unode);
+			conf_free_list(princ_list);
 			return -ENOENT;
 		}
 
@@ -379,6 +383,7 @@ static int static_init(void) {
 			warnx("static_init: calloc (1, %lu) failed",
 				(unsigned long)sizeof *gnode);
 			free(gr);
+			conf_free_list(princ_list);
 			return -ENOMEM;
 		}
 		gnode->gid = gr->gr_gid;
@@ -387,6 +392,9 @@ static int static_init(void) {
 		gnode->localgroup = conf_get_str("Static", cln->field);
 		if (!gnode->localgroup) {
 			free(gr);
+			free(gnode->principal);
+			free(gnode);
+			conf_free_list(princ_list);
 			return -ENOENT;
 		}
 
@@ -394,6 +402,8 @@ static int static_init(void) {
 
 		LIST_INSERT_HEAD (&gid_mappings[gid_hash(gnode->gid)], gnode, link);
 	}
+	
+	conf_free_list(princ_list);
 	return 0;
 }
 
Signature · 1 line
2.20.1
#10 lore raw

PATCH 10/19 Removed a resource leak from nsm/file.c

In reply to Steve Dickson

nsm/file.c:536: leaked_handle: Handle variable "fd" going
out of scope leaks the handle

---
 support/nsm/file.c | 1 +
 1 file changed, 1 insertion(+)
support/nsm/file.c +1 -0
index 52f5401..0b66f12 100644
@@ -533,6 +533,7 @@ nsm_update_kernel_state(const int state)
 	len = snprintf(buf, sizeof(buf), "%d", state);
 	if (error_check(len, sizeof(buf))) {
 		xlog_warn("Failed to form NSM state number string");
+		close(fd);
 		return;
 	}
 
Signature · 1 line
2.20.1
#11 lore raw

PATCH 11/19 Removed resource leaks from systemd/rpc-pipefs-generator.c

In reply to Steve Dickson

systemd/rpc-pipefs-generator.c:73: leaked_storage: Variable "pipefs_unit"
going out of scope leaks the storage it points to
systemd/rpc-pipefs-generator.c:77: leaked_storage: Variable "pipefs_unit"
going out of scope leaks the storage it points to.
systemd/rpc-pipefs-generator.c:85: leaked_storage: Variable "pipefs_unit"
going out of scope leaks the storage it points to.
systemd/rpc-pipefs-generator.c:94: leaked_storage: Variable "pipefs_unit"
going out of scope leaks the storage it points to.

---
 systemd/rpc-pipefs-generator.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
systemd/rpc-pipefs-generator.c +8 -2
index 0b5da11..8e218aa 100644
@@ -69,12 +69,16 @@ int generate_target(char *pipefs_path, const char *dirname)
 		return 1;
 
 	ret = generate_mount_unit(pipefs_path, pipefs_unit, dirname);
-	if (ret)
+	if (ret) {
+		free(pipefs_unit);
 		return ret;
+	}
 
 	path = malloc(strlen(dirname) + 1 + sizeof(filebase));
-	if (!path)
+	if (!path) {
+		free(pipefs_unit);
 		return 2;
+	}
 	sprintf(path, "%s", dirname);
 	mkdir(path, 0755);
 	strcat(path, filebase);
@@ -82,6 +86,7 @@ int generate_target(char *pipefs_path, const char *dirname)
 	if (!f)
 	{
 		free(path);
+		free(pipefs_unit);
 		return 1;
 	}
 
@@ -90,6 +95,7 @@ int generate_target(char *pipefs_path, const char *dirname)
 	fprintf(f, "After=%s\n", pipefs_unit);
 	fclose(f);
 	free(path);
+	free(pipefs_unit);
 
 	return 0;
 }
Signature · 1 line
2.20.1
#12 lore raw

PATCH 12/19 Removed resource leaks from blkmapd/device-discovery.c

In reply to Steve Dickson

blkmapd/device-discovery.c:190: leaked_storage: Variable "serial"
going out of scope leaks the storage it points to.

blkmapd/device-discovery.c:378: overwrite_var: Overwriting handle
"bl_pipe_fd" in "bl_pipe_fd = open(bl_pipe_file, 2)" leaks the handle.

---
 utils/blkmapd/device-discovery.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
utils/blkmapd/device-discovery.c +21 -1
index 2ce60f8..e811703 100644
@@ -186,8 +186,13 @@ static void bl_add_disk(char *filepath)
 		}
 	}
 
-	if (disk && diskpath)
+	if (disk && diskpath) {
+		if (serial) {
+			free(serial->data);
+			free(serial);
+		}
 		return;
+	}
 
 	/* add path */
 	path = malloc(sizeof(struct bl_disk_path));
@@ -223,6 +228,10 @@ static void bl_add_disk(char *filepath)
 			disk->size = size;
 			disk->valid_path = path;
 		}
+		if (serial) {
+			free(serial->data);
+			free(serial);
+		}
 	}
 	return;
 
@@ -232,6 +241,10 @@ static void bl_add_disk(char *filepath)
 			free(path->full_path);
 		free(path);
 	}
+	if (serial) {
+		free(serial->data);
+		free(serial);
+	}
 	return;
 }
 
@@ -375,7 +388,12 @@ static void bl_rpcpipe_cb(void)
 			if (event->mask & IN_CREATE) {
 				BL_LOG_WARNING("nfs pipe dir created\n");
 				bl_watch_dir(nfspipe_dir, &nfs_pipedir_wfd);
+				if (bl_pipe_fd >= 0)
+					close(bl_pipe_fd);
 				bl_pipe_fd = open(bl_pipe_file, O_RDWR);
+				if (bl_pipe_fd < 0)
+					BL_LOG_ERR("open %s failed: %s\n",
+						event->name, strerror(errno));
 			} else if (event->mask & IN_DELETE) {
 				BL_LOG_WARNING("nfs pipe dir deleted\n");
 				inotify_rm_watch(bl_watch_fd, nfs_pipedir_wfd);
@@ -388,6 +406,8 @@ static void bl_rpcpipe_cb(void)
 				continue;
 			if (event->mask & IN_CREATE) {
 				BL_LOG_WARNING("blocklayout pipe file created\n");
+				if (bl_pipe_fd >= 0)
+					close(bl_pipe_fd);
 				bl_pipe_fd = open(bl_pipe_file, O_RDWR);
 				if (bl_pipe_fd < 0)
 					BL_LOG_ERR("open %s failed: %s\n",
Signature · 1 line
2.20.1
#13 lore raw

PATCH 13/19 Removed resource leaks from gssd/krb5_util.c

In reply to Steve Dickson

gssd/krb5_util.c:696: overwrite_var: Overwriting "k5err" in
"k5err = gssd_k5_err_msg(context, code)" leaks the storage that "k5err" points to.

gssd/krb5_util.c:737: overwrite_var: Overwriting "k5err" in
"k5err = gssd_k5_err_msg(context, code)" leaks the storage that "k5err" points to.

gssd/krb5_util.c:899: overwrite_var: Overwriting "k5err" in
"k5err = gssd_k5_err_msg(context, code)" leaks the storage that "k5err" points to.

krb5_util.c:1173: leaked_storage: Variable "l" going out
of scope leaks the storage it points to.

---
 utils/gssd/krb5_util.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
utils/gssd/krb5_util.c +8 -1
index 6daba44..454a6eb 100644
@@ -699,6 +699,8 @@ gssd_search_krb5_keytab(krb5_context context, krb5_keytab kt,
 				 "we failed to unparse principal name: %s\n",
 				 k5err);
 			k5_free_kt_entry(context, kte);
+			free(k5err);
+			k5err = NULL;
 			continue;
 		}
 		printerr(4, "Processing keytab entry for principal '%s'\n",
@@ -900,6 +902,8 @@ find_keytab_entry(krb5_context context, krb5_keytab kt,
 				k5err = gssd_k5_err_msg(context, code);
 				printerr(1, "%s while building principal for '%s'\n",
 					 k5err, spn);
+				free(k5err);
+				k5err = NULL;
 				continue;
 			}
 			code = krb5_kt_get_entry(context, kt, princ, 0, 0, kte);
@@ -1169,7 +1173,8 @@ gssd_get_krb5_machine_cred_list(char ***list)
 		*list = l;
 		retval = 0;
 		goto out;
-	}
+	} else
+		free((void *)l);
   out:
 	return retval;
 }
@@ -1217,6 +1222,8 @@ gssd_destroy_krb5_machine_creds(void)
 			printerr(0, "WARNING: %s while resolving credential "
 				    "cache '%s' for destruction\n", k5err,
 				    ple->ccname);
+			free(k5err);
+			k5err = NULL;
 			continue;
 		}
 
Signature · 1 line
2.20.1
#14 lore raw

PATCH 14/19 Removed a resource leak from mount/configfile.c

In reply to Steve Dickson

mount/configfile.c:410: leaked_storage: Variable "config_opts"
going out of scope leaks the storage it points to.

---
 utils/mount/configfile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
utils/mount/configfile.c +1 -1
index b48b25e..93fe500 100644
@@ -404,7 +404,7 @@ char *conf_get_mntopts(char *spec, char *mount_point,
 
 	/* list_size + optlen + ',' + '\0' */
 	config_opts = calloc(1, (list_size+optlen+2));
-	if (server == NULL) {
+	if (config_opts == NULL) {
 		xlog_warn("conf_get_mountops: Unable calloc memory for config_opts"); 
 		free_all();
 		return mount_opts;
Signature · 1 line
2.20.1
#15 lore raw

PATCH 15/19 Removed a resource leak from mount/nfsmount.c

In reply to Steve Dickson

mount/nfsmount.c:455: leaked_storage: Variable "mounthost" going
out of scope leaks the storage it points to.

---
 utils/mount/nfsmount.c | 1 +
 1 file changed, 1 insertion(+)
utils/mount/nfsmount.c +1 -0
index 952a755..3d95da9 100644
@@ -452,6 +452,7 @@ parse_options(char *old_opts, struct nfs_mount_data *data,
 	nfs_error(_("%s: Bad nfs mount parameter: %s\n"), progname, opt);
  out_bad:
 	free(tmp_opts);
+	free(mounthost);
 	return 0;
 }
 
Signature · 1 line
2.20.1
#16 lore raw

PATCH 16/19 Removed a resource leak from mount/stropts.c

In reply to Steve Dickson

mount/stropts.c:986: leaked_storage: Variable "address"
going out of scope leaks the storage it points to.

---
 utils/mount/stropts.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
utils/mount/stropts.c +4 -1
index a093926..1bb7a73 100644
@@ -983,8 +983,11 @@ static int nfs_try_mount(struct nfsmount_info *mi)
 		}
 
 		if (!nfs_append_addr_option(address->ai_addr,
-					    address->ai_addrlen, mi->options))
+					    address->ai_addrlen, mi->options)) {
+			nfs_freeaddrinfo(address);
+			errno = ENOMEM;
 			return 0;
+		}
 		mi->address = address;
 	}
 
Signature · 1 line
2.20.1
#17 lore raw

PATCH 17/19 Removed resource leaks from mountd/cache.c

In reply to Steve Dickson

mountd/cache.c:1244:3: warning: statement will never be
executed [-Wswitch-unreachable]

mountd/cache.c:1260: leaked_storage: Variable "locations"
going out of scope leaks the storage it points to.

---
 utils/mountd/cache.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
utils/mountd/cache.c +3 -2
index 2cb370f..bdbd190 100644
@@ -1240,7 +1240,7 @@ static struct exportent *lookup_junction(char *dom, const char *pathname,
 		goto out;
 	}
 	status = nfs_get_basic_junction(pathname, &locations);
-	switch (status) {
+	if (status) {
 		xlog(L_WARNING, "Dangling junction %s: %s",
 			pathname, strerror(status));
 		goto out;
@@ -1248,10 +1248,11 @@ static struct exportent *lookup_junction(char *dom, const char *pathname,
 
 	parent = lookup_parent_export(dom, pathname, ai);
 	if (parent == NULL)
-		goto out;
+		goto free_locations;
 
 	exp = locations_to_export(locations, pathname, parent);
 
+free_locations:
 	nfs_free_locations(locations->ns_list);
 	free(locations);
 
Signature · 1 line
2.20.1
#18 lore raw

PATCH 18/19 Removed a resource leak from mountd/fsloc.c

In reply to Steve Dickson

mountd/fsloc.c:97: overwrite_var: Overwriting "mp" in
"mp = calloc(1UL, 16UL)" leaks the storage that "mp" points to.

---
 utils/mountd/fsloc.c | 1 +
 1 file changed, 1 insertion(+)
utils/mountd/fsloc.c +1 -0
index bc737d1..cf42944 100644
@@ -102,6 +102,7 @@ static struct servers *parse_list(char **list)
 		cp = strchr(list[i], '@');
 		if ((!cp) || list[i][0] != '/') {
 			xlog(L_WARNING, "invalid entry '%s'", list[i]);
+			free(mp);
 			continue; /* XXX Need better error handling */
 		}
 		res->h_mp[i] = mp;
Signature · 1 line
2.20.1
#19 lore raw

PATCH 19/19 Removed a resource leak from nfsdcltrack/sqlite.c

In reply to Steve Dickson

nfsdcltrack/sqlite.c:218: leaked_storage: Variable "err" going out
of scope leaks the storage it points to.

---
 utils/nfsdcltrack/sqlite.c | 2 ++
 1 file changed, 2 insertions(+)
utils/nfsdcltrack/sqlite.c +2 -0
index c59f777..2801201 100644
@@ -215,6 +215,8 @@ sqlite_maindb_init_v2(void)
 				&err);
 	if (ret != SQLITE_OK) {
 		xlog(L_ERROR, "Unable to begin transaction: %s", err);
+		if (err)
+			sqlite3_free(err);
 		return ret;
 	}
 
Signature · 1 line
2.20.1
#20 lore raw
In reply to Steve Dickson
Quoted 54 lines · Steve Dickson

Red Hat is now requiring covertity scans to be run against all RHEL 8 packages.

These patches removed the majority of the resource leaks that were flagged by the scan.

Most of the leaks were in return and error paths as well as some obvious problems like checking the wrong point to be NULL.

There are still a few resources leaks and used_after_freed being flagged but I am thinking they false-positives because I just don't see the problem.

I've tested these patches for a couple days and they seem stable... but whenever free()s are added... So is risk of freeing that is still being used. Plus they will get a good workout at the upcoming Bakeathon.

Steve Dickson (19):
Removed resource leaks from junction/path.c Removed resource leaks from nfs/exports.c Removed a resource leak from nfs/mydaemon.c Removed a resource leak from nfs/rpcmisc.c Removed a resource leak from nfs/svc_socket.c Removed bad frees from nfs/xcommon.c
Removed resource leaks from nfs/xlog.c
Removed resource leaks from nfsidmap/libnfsidmap.c Removed resource leaks from nfsidmap/static.c Removed a resource leak from nsm/file.c
Removed resource leaks from systemd/rpc-pipefs-generator.c Removed resource leaks from blkmapd/device-discovery.c Removed resource leaks from gssd/krb5_util.c Removed a resource leak from mount/configfile.c Removed a resource leak from mount/nfsmount.c Removed a resource leak from mount/stropts.c Removed resource leaks from mountd/cache.c Removed a resource leak from mountd/fsloc.c Removed a resource leak from nfsdcltrack/sqlite.c

 support/junction/path.c          |  6 +++++-
 support/nfs/exports.c            |  2 ++
 support/nfs/mydaemon.c           |  1 +
 support/nfs/rpcmisc.c            |  1 +
 support/nfs/svc_socket.c         |  1 +
 support/nfs/xcommon.c            | 14 ++++++++++----
 support/nfs/xlog.c               |  6 +++++-
 support/nfsidmap/libnfsidmap.c   | 10 ++++++++--
 support/nfsidmap/static.c        | 10 ++++++++++
 support/nsm/file.c               |  1 +
 systemd/rpc-pipefs-generator.c   | 10 ++++++++--
 utils/blkmapd/device-discovery.c | 22 +++++++++++++++++++++-
Quoted 9 lines
 utils/gssd/krb5_util.c           |  9 ++++++++-
 utils/mount/configfile.c         |  2 +-
 utils/mount/nfsmount.c           |  1 +
 utils/mount/stropts.c            |  5 ++++-
 utils/mountd/cache.c             |  5 +++--
 utils/mountd/fsloc.c             |  1 +
 utils/nfsdcltrack/sqlite.c       |  2 ++
 19 files changed, 93 insertions(+), 16 deletions(-)

Committed...

steved.