Ian Kent f53fbf
autofs-5.1.4 - covarity fixes 1
Ian Kent f53fbf
Ian Kent f53fbf
From: Ian Kent <raven@themaw.net>
Ian Kent f53fbf
Ian Kent f53fbf
* remove conditional close of nullfd.
Ian Kent f53fbf
* fix memory leak of local_domain in lib/macros.c:macro_init().
Ian Kent f53fbf
* check for NULL prior to several assignments in lib/master_parse.y.
Ian Kent f53fbf
* fix memory leak in lib/mounts.c:add_std_amd_vars().
Ian Kent f53fbf
* add missing break in lib/rpc_subs.c:rpc_get_netid().
Ian Kent f53fbf
* fix variable scope problem in modules/amd_parse.c:make_selector().
Ian Kent f53fbf
* fix selector itself not freed in lib/parse_subs.c:free_selector().
Ian Kent f53fbf
* fix possible memory leak in modules/lookup_ldap.c:parse_ldap_config().
Ian Kent f53fbf
* fix possible memory leak in modules/lookup_ldap.c:decode_percent_hack().
Ian Kent f53fbf
* fix usage of decode_percent_hack() in modules/lookup_ldap.c.
Ian Kent f53fbf
* initialize enc_key1 and enc_key2 in modules/lookup_ldap.c:lookup_one().
Ian Kent f53fbf
* fix double alloc of map_type in modules/parse_amd.c:make_default_entry().
Ian Kent f53fbf
* fix double alloc of map_type in modules/parse_amd.c:get_defaults_entry().
Ian Kent f53fbf
* fix possible memory leak in modules/parse_sun.c:parse_reinit().
Ian Kent f53fbf
* initialize myoptions and ro_loc in modules/parse_sun.c:mount_subtree().
Ian Kent f53fbf
* initialize myoptions and loc in modules/parse_sun.c:parse_mount().
Ian Kent f53fbf
Ian Kent f53fbf
Signed-off-by: Ian Kent <raven@themaw.net>
Ian Kent f53fbf
---
Ian Kent f53fbf
 lib/log.c             |    3 +--
Ian Kent f53fbf
 lib/macros.c          |    1 +
Ian Kent f53fbf
 lib/master_parse.y    |   28 ++++++++++++++++++++++++++++
Ian Kent f53fbf
 lib/mounts.c          |    4 +++-
Ian Kent f53fbf
 lib/parse_subs.c      |    1 +
Ian Kent f53fbf
 lib/rpc_subs.c        |    1 +
Ian Kent f53fbf
 modules/amd_parse.y   |    4 ++--
Ian Kent f53fbf
 modules/lookup_ldap.c |   27 ++++++++++++++++++++++-----
Ian Kent f53fbf
 modules/parse_amd.c   |    4 ++--
Ian Kent f53fbf
 modules/parse_sun.c   |   10 +++++++++-
Ian Kent f53fbf
 10 files changed, 70 insertions(+), 13 deletions(-)
Ian Kent f53fbf
Ian Kent f53fbf
diff --git a/lib/log.c b/lib/log.c
Ian Kent f53fbf
index 1a0bc3fa..f6ab77c1 100644
Ian Kent f53fbf
--- a/lib/log.c
Ian Kent f53fbf
+++ b/lib/log.c
Ian Kent f53fbf
@@ -336,8 +336,7 @@ void log_to_syslog(void)
Ian Kent f53fbf
 		exit(1);
Ian Kent f53fbf
 	}
Ian Kent f53fbf
 
Ian Kent f53fbf
-	if (nullfd > 2)
Ian Kent f53fbf
-		close(nullfd);
Ian Kent f53fbf
+	close(nullfd);
Ian Kent f53fbf
 
Ian Kent f53fbf
 	return;
Ian Kent f53fbf
 }
Ian Kent f53fbf
diff --git a/lib/macros.c b/lib/macros.c
Ian Kent f53fbf
index dfdca857..5def26da 100644
Ian Kent f53fbf
--- a/lib/macros.c
Ian Kent f53fbf
+++ b/lib/macros.c
Ian Kent f53fbf
@@ -137,6 +137,7 @@ void macro_init(void)
Ian Kent f53fbf
 
Ian Kent f53fbf
 	macro_init_done = 1;
Ian Kent f53fbf
 	macro_unlock();
Ian Kent f53fbf
+	free(local_domain);
Ian Kent f53fbf
 	return;
Ian Kent f53fbf
 }
Ian Kent f53fbf
 
Ian Kent f53fbf
diff --git a/lib/master_parse.y b/lib/master_parse.y
Ian Kent f53fbf
index 761ade9b..5d687a70 100644
Ian Kent f53fbf
--- a/lib/master_parse.y
Ian Kent f53fbf
+++ b/lib/master_parse.y
Ian Kent f53fbf
@@ -157,6 +157,8 @@ line:
Ian Kent f53fbf
 
Ian Kent f53fbf
 		trim_maptype($2);
Ian Kent f53fbf
 
Ian Kent f53fbf
+		if (path)
Ian Kent f53fbf
+			free(path);
Ian Kent f53fbf
 		path = master_strdup($1);
Ian Kent f53fbf
 		if (!path) {
Ian Kent f53fbf
 			master_error("memory allocation error");
Ian Kent f53fbf
@@ -167,6 +169,8 @@ line:
Ian Kent f53fbf
 		if ((tmp = strchr($2, ',')))
Ian Kent f53fbf
 			*tmp++ = '\0';
Ian Kent f53fbf
 
Ian Kent f53fbf
+		if (type)
Ian Kent f53fbf
+			free(type);
Ian Kent f53fbf
 		type = master_strdup($2);
Ian Kent f53fbf
 		if (!type) {
Ian Kent f53fbf
 			master_error("memory allocation error");
Ian Kent f53fbf
@@ -174,6 +178,8 @@ line:
Ian Kent f53fbf
 			YYABORT;
Ian Kent f53fbf
 		}
Ian Kent f53fbf
 		if (tmp) {
Ian Kent f53fbf
+			if (format)
Ian Kent f53fbf
+				free(format);
Ian Kent f53fbf
 			format = master_strdup(tmp);
Ian Kent f53fbf
 			if (!format) {
Ian Kent f53fbf
 				master_error("memory allocation error");
Ian Kent f53fbf
@@ -204,6 +210,8 @@ line:
Ian Kent f53fbf
 
Ian Kent f53fbf
 mapspec: map
Ian Kent f53fbf
 	{
Ian Kent f53fbf
+		if (local_argv)
Ian Kent f53fbf
+			free_argv(local_argc, (const char **) local_argv);
Ian Kent f53fbf
 		local_argc = tmp_argc;
Ian Kent f53fbf
 		local_argv = tmp_argv;
Ian Kent f53fbf
 		tmp_argc = 0;
Ian Kent f53fbf
@@ -211,6 +219,8 @@ mapspec: map
Ian Kent f53fbf
 	}
Ian Kent f53fbf
 	| map options
Ian Kent f53fbf
 	{
Ian Kent f53fbf
+		if (local_argv)
Ian Kent f53fbf
+			free_argv(local_argc, (const char **) local_argv);
Ian Kent f53fbf
 		local_argc = tmp_argc;
Ian Kent f53fbf
 		local_argv = tmp_argv;
Ian Kent f53fbf
 		tmp_argc = 0;
Ian Kent f53fbf
@@ -288,6 +298,8 @@ map:	PATH
Ian Kent f53fbf
 	}
Ian Kent f53fbf
 	| MAPHOSTS
Ian Kent f53fbf
 	{
Ian Kent f53fbf
+		if (type)
Ian Kent f53fbf
+			free(type);
Ian Kent f53fbf
 		type = master_strdup($1 + 1);
Ian Kent f53fbf
 		if (!type) {
Ian Kent f53fbf
 			local_free_vars();
Ian Kent f53fbf
@@ -302,6 +314,8 @@ map:	PATH
Ian Kent f53fbf
 	}
Ian Kent f53fbf
 	| MAPNULL
Ian Kent f53fbf
 	{
Ian Kent f53fbf
+		if (type)
Ian Kent f53fbf
+			free(type);
Ian Kent f53fbf
 		type = master_strdup($1 + 1);
Ian Kent f53fbf
 		if (!type) {
Ian Kent f53fbf
 			local_free_vars();
Ian Kent f53fbf
@@ -310,6 +324,8 @@ map:	PATH
Ian Kent f53fbf
 	}
Ian Kent f53fbf
 	| dnattrs
Ian Kent f53fbf
 	{
Ian Kent f53fbf
+		if (type)
Ian Kent f53fbf
+			free(type);
Ian Kent f53fbf
 		type = master_strdup("ldap");
Ian Kent f53fbf
 		if (!type) {
Ian Kent f53fbf
 			local_free_vars();
Ian Kent f53fbf
@@ -332,6 +348,8 @@ map:	PATH
Ian Kent f53fbf
 		if ((tmp = strchr($1, ',')))
Ian Kent f53fbf
 			*tmp++ = '\0';
Ian Kent f53fbf
 
Ian Kent f53fbf
+		if (type)
Ian Kent f53fbf
+			free(type);
Ian Kent f53fbf
 		if (strcmp($1, "exec"))
Ian Kent f53fbf
 			type = master_strdup($1);
Ian Kent f53fbf
 		else
Ian Kent f53fbf
@@ -342,6 +360,8 @@ map:	PATH
Ian Kent f53fbf
 			YYABORT;
Ian Kent f53fbf
 		}
Ian Kent f53fbf
 		if (tmp) {
Ian Kent f53fbf
+			if (format)
Ian Kent f53fbf
+				free(format);
Ian Kent f53fbf
 			format = master_strdup(tmp);
Ian Kent f53fbf
 			if (!format) {
Ian Kent f53fbf
 				master_error("memory allocation error");
Ian Kent f53fbf
@@ -366,6 +386,8 @@ map:	PATH
Ian Kent f53fbf
 		if ((tmp = strchr($1, ',')))
Ian Kent f53fbf
 			*tmp++ = '\0';
Ian Kent f53fbf
 
Ian Kent f53fbf
+		if (type)
Ian Kent f53fbf
+			free(type);
Ian Kent f53fbf
 		if (strcmp($1, "exec"))
Ian Kent f53fbf
 			type = master_strdup($1);
Ian Kent f53fbf
 		else
Ian Kent f53fbf
@@ -376,6 +398,8 @@ map:	PATH
Ian Kent f53fbf
 			YYABORT;
Ian Kent f53fbf
 		}
Ian Kent f53fbf
 		if (tmp) {
Ian Kent f53fbf
+			if (format)
Ian Kent f53fbf
+				free(format);
Ian Kent f53fbf
 			format = master_strdup(tmp);
Ian Kent f53fbf
 			if (!format) {
Ian Kent f53fbf
 				master_error("memory allocation error");
Ian Kent f53fbf
@@ -400,6 +424,8 @@ map:	PATH
Ian Kent f53fbf
 		if ((tmp = strchr($1, ',')))
Ian Kent f53fbf
 			*tmp++ = '\0';
Ian Kent f53fbf
 
Ian Kent f53fbf
+		if (type)
Ian Kent f53fbf
+			free(type);
Ian Kent f53fbf
 		if (strcmp($1, "exec"))
Ian Kent f53fbf
 			type = master_strdup($1);
Ian Kent f53fbf
 		else
Ian Kent f53fbf
@@ -410,6 +436,8 @@ map:	PATH
Ian Kent f53fbf
 			YYABORT;
Ian Kent f53fbf
 		}
Ian Kent f53fbf
 		if (tmp) {
Ian Kent f53fbf
+			if (format)
Ian Kent f53fbf
+				free(format);
Ian Kent f53fbf
 			format = master_strdup(tmp);
Ian Kent f53fbf
 			if (!format) {
Ian Kent f53fbf
 				master_error("memory allocation error");
Ian Kent f53fbf
diff --git a/lib/mounts.c b/lib/mounts.c
Ian Kent f53fbf
index f46fab2b..a35503bf 100644
Ian Kent f53fbf
--- a/lib/mounts.c
Ian Kent f53fbf
+++ b/lib/mounts.c
Ian Kent f53fbf
@@ -489,8 +489,10 @@ void add_std_amd_vars(struct substvar *sv)
Ian Kent f53fbf
 		const struct substvar *v = macro_findvar(sv, "domain", 4);
Ian Kent f53fbf
 		if (v && *v->val) {
Ian Kent f53fbf
 			tmp = strdup(v->val);
Ian Kent f53fbf
-			if (tmp)
Ian Kent f53fbf
+			if (tmp) {
Ian Kent f53fbf
 				macro_global_addvar("cluster", 7, tmp);
Ian Kent f53fbf
+				free(tmp);
Ian Kent f53fbf
+			}
Ian Kent f53fbf
 		}
Ian Kent f53fbf
 	}
Ian Kent f53fbf
 
Ian Kent f53fbf
diff --git a/lib/parse_subs.c b/lib/parse_subs.c
Ian Kent f53fbf
index 841e81fd..cdda2e1a 100644
Ian Kent f53fbf
--- a/lib/parse_subs.c
Ian Kent f53fbf
+++ b/lib/parse_subs.c
Ian Kent f53fbf
@@ -189,6 +189,7 @@ void free_selector(struct selector *selector)
Ian Kent f53fbf
 			free(s->func.arg2);
Ian Kent f53fbf
 		s = next;
Ian Kent f53fbf
 	}
Ian Kent f53fbf
+	free(selector);
Ian Kent f53fbf
 	return;
Ian Kent f53fbf
 }
Ian Kent f53fbf
 
Ian Kent f53fbf
diff --git a/lib/rpc_subs.c b/lib/rpc_subs.c
Ian Kent f53fbf
index 9451c455..8b23627a 100644
Ian Kent f53fbf
--- a/lib/rpc_subs.c
Ian Kent f53fbf
+++ b/lib/rpc_subs.c
Ian Kent f53fbf
@@ -389,6 +389,7 @@ static enum clnt_stat rpc_get_netid(const sa_family_t family,
Ian Kent f53fbf
 		}
Ian Kent f53fbf
 
Ian Kent f53fbf
 		*netid = nc_netid;
Ian Kent f53fbf
+		break;
Ian Kent f53fbf
 	}
Ian Kent f53fbf
 	endnetconfig(handle);
Ian Kent f53fbf
 	free(nc_proto);
Ian Kent f53fbf
diff --git a/modules/amd_parse.y b/modules/amd_parse.y
Ian Kent f53fbf
index 1d72f190..5bd688d9 100644
Ian Kent f53fbf
--- a/modules/amd_parse.y
Ian Kent f53fbf
+++ b/modules/amd_parse.y
Ian Kent f53fbf
@@ -822,13 +822,13 @@ static int make_selector(char *name,
Ian Kent f53fbf
 		if (!value1)
Ian Kent f53fbf
 			tmp = NULL;
Ian Kent f53fbf
 		else {
Ian Kent f53fbf
-			char *tmp = amd_strdup(value1);
Ian Kent f53fbf
+			tmp = amd_strdup(value1);
Ian Kent f53fbf
 			if (!tmp)
Ian Kent f53fbf
 				goto error;
Ian Kent f53fbf
 		}
Ian Kent f53fbf
 		s->func.arg1 = tmp;
Ian Kent f53fbf
 	} else if (s->sel->flags & SEL_FLAG_FUNC2) {
Ian Kent f53fbf
-		char *tmp = amd_strdup(value1);
Ian Kent f53fbf
+		tmp = amd_strdup(value1);
Ian Kent f53fbf
 		if (!tmp)
Ian Kent f53fbf
 			goto error;
Ian Kent f53fbf
 		s->func.arg1 = tmp;
Ian Kent f53fbf
diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
Ian Kent f53fbf
index 37810e1c..06c96973 100644
Ian Kent f53fbf
--- a/modules/lookup_ldap.c
Ian Kent f53fbf
+++ b/modules/lookup_ldap.c
Ian Kent f53fbf
@@ -1137,6 +1137,7 @@ int parse_ldap_config(unsigned logopt, struct lookup_context *ctxt)
Ian Kent f53fbf
 		error(logopt,
Ian Kent f53fbf
 		      MODPREFIX "stat(2) failed with error %s.",
Ian Kent f53fbf
 		      strerror(errno));
Ian Kent f53fbf
+		free(auth_conf);
Ian Kent f53fbf
 		return 0;
Ian Kent f53fbf
 	}
Ian Kent f53fbf
 
Ian Kent f53fbf
@@ -1148,6 +1149,7 @@ int parse_ldap_config(unsigned logopt, struct lookup_context *ctxt)
Ian Kent f53fbf
 		      "Please make sure that it is owned by root, group "
Ian Kent f53fbf
 		      "is root, and the mode is 0600.",
Ian Kent f53fbf
 		      auth_conf);
Ian Kent f53fbf
+		free(auth_conf);
Ian Kent f53fbf
 		return -1;
Ian Kent f53fbf
 	}
Ian Kent f53fbf
 
Ian Kent f53fbf
@@ -1182,9 +1184,11 @@ int parse_ldap_config(unsigned logopt, struct lookup_context *ctxt)
Ian Kent f53fbf
 		goto out;
Ian Kent f53fbf
 	}
Ian Kent f53fbf
 
Ian Kent f53fbf
-	if (!usetls || ctxt->port == LDAPS_PORT)
Ian Kent f53fbf
+	if (!usetls || ctxt->port == LDAPS_PORT) {
Ian Kent f53fbf
 		use_tls = LDAP_TLS_DONT_USE;
Ian Kent f53fbf
-	else {
Ian Kent f53fbf
+		if (usetls)
Ian Kent f53fbf
+			free(usetls);
Ian Kent f53fbf
+	} else {
Ian Kent f53fbf
 		if (!strcasecmp(usetls, "yes"))
Ian Kent f53fbf
 			use_tls = LDAP_TLS_INIT;
Ian Kent f53fbf
 		else if (!strcasecmp(usetls, "no"))
Ian Kent f53fbf
@@ -1194,6 +1198,7 @@ int parse_ldap_config(unsigned logopt, struct lookup_context *ctxt)
Ian Kent f53fbf
 			      MODPREFIX
Ian Kent f53fbf
 			      "The usetls property must have value "
Ian Kent f53fbf
 			      "\"yes\" or \"no\".");
Ian Kent f53fbf
+			free(usetls);
Ian Kent f53fbf
 			ret = -1;
Ian Kent f53fbf
 			goto out;
Ian Kent f53fbf
 		}
Ian Kent f53fbf
@@ -1221,6 +1226,7 @@ int parse_ldap_config(unsigned logopt, struct lookup_context *ctxt)
Ian Kent f53fbf
 			      MODPREFIX
Ian Kent f53fbf
 			      "The tlsrequired property must have value "
Ian Kent f53fbf
 			      "\"yes\" or \"no\".");
Ian Kent f53fbf
+			free(tlsrequired);
Ian Kent f53fbf
 			ret = -1;
Ian Kent f53fbf
 			goto out;
Ian Kent f53fbf
 		}
Ian Kent f53fbf
@@ -1252,6 +1258,7 @@ int parse_ldap_config(unsigned logopt, struct lookup_context *ctxt)
Ian Kent f53fbf
 			      MODPREFIX
Ian Kent f53fbf
 			      "The authrequired property must have value "
Ian Kent f53fbf
 			      "\"yes\", \"no\", \"autodetect\", or \"simple\".");
Ian Kent f53fbf
+			free(authrequired);
Ian Kent f53fbf
 			ret = -1;
Ian Kent f53fbf
 			goto out;
Ian Kent f53fbf
 		}
Ian Kent f53fbf
@@ -1338,6 +1345,7 @@ auth_fail:
Ian Kent f53fbf
 	(void)get_property(logopt, root, "credentialcache", &client_cc);
Ian Kent f53fbf
 
Ian Kent f53fbf
 	ctxt->auth_conf = auth_conf;
Ian Kent f53fbf
+	auth_conf = NULL;
Ian Kent f53fbf
 	ctxt->use_tls = use_tls;
Ian Kent f53fbf
 	ctxt->tls_required = tls_required;
Ian Kent f53fbf
 	ctxt->auth_required = auth_required;
Ian Kent f53fbf
@@ -1375,8 +1383,12 @@ auth_fail:
Ian Kent f53fbf
 		      user, secret ? "specified" : "unspecified",
Ian Kent f53fbf
 		      client_princ, client_cc);
Ian Kent f53fbf
 	}
Ian Kent f53fbf
+	if (authtype)
Ian Kent f53fbf
+		free(authtype);
Ian Kent f53fbf
 out:
Ian Kent f53fbf
 	xmlFreeDoc(doc);
Ian Kent f53fbf
+	if (auth_conf)
Ian Kent f53fbf
+		free(auth_conf);
Ian Kent f53fbf
 
Ian Kent f53fbf
 	if (fallback)
Ian Kent f53fbf
 		return 0;
Ian Kent f53fbf
@@ -1986,7 +1998,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
Ian Kent f53fbf
 			}
Ian Kent f53fbf
 		} else if (count == 1) {
Ian Kent f53fbf
 			dec_len = decode_percent_hack(keyValue[0], &key);
Ian Kent f53fbf
-			if (dec_len < 0) {
Ian Kent f53fbf
+			if (dec_len <= 0) {
Ian Kent f53fbf
 				error(logopt, MODPREFIX
Ian Kent f53fbf
 				      "invalid map key %s - ignoring",
Ian Kent f53fbf
 				      *keyValue);
Ian Kent f53fbf
@@ -1994,7 +2006,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
Ian Kent f53fbf
 			}
Ian Kent f53fbf
 		} else {
Ian Kent f53fbf
 			dec_len = decode_percent_hack(keyValue[0], &key);
Ian Kent f53fbf
-			if (dec_len < 0) {
Ian Kent f53fbf
+			if (dec_len <= 0) {
Ian Kent f53fbf
 				error(logopt, MODPREFIX
Ian Kent f53fbf
 				      "invalid map key %s - ignoring",
Ian Kent f53fbf
 				      *keyValue);
Ian Kent f53fbf
@@ -2004,7 +2016,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
Ian Kent f53fbf
 			for (i = 1; i < count; i++) {
Ian Kent f53fbf
 				char *k;
Ian Kent f53fbf
 				dec_len = decode_percent_hack(keyValue[i], &k);
Ian Kent f53fbf
-				if (dec_len < 0) {
Ian Kent f53fbf
+				if (dec_len <= 0) {
Ian Kent f53fbf
 					error(logopt, MODPREFIX
Ian Kent f53fbf
 					      "invalid map key %s - ignoring",
Ian Kent f53fbf
 					      *keyValue);
Ian Kent f53fbf
@@ -2159,6 +2171,8 @@ static int decode_percent_hack(const char *name, char **key)
Ian Kent f53fbf
 	*key = NULL;
Ian Kent f53fbf
 
Ian Kent f53fbf
 	len = get_percent_decoded_len(name);
Ian Kent f53fbf
+	if (!len)
Ian Kent f53fbf
+		return 0;
Ian Kent f53fbf
 	new = malloc(len + 1);
Ian Kent f53fbf
 	if (!new)
Ian Kent f53fbf
 		return -1;
Ian Kent f53fbf
@@ -2998,6 +3012,9 @@ static int lookup_one(struct autofs_point *ap, struct map_source *source,
Ian Kent f53fbf
 	attrs[1] = info;
Ian Kent f53fbf
 	attrs[2] = NULL;
Ian Kent f53fbf
 
Ian Kent f53fbf
+	enc_key1 = NULL;
Ian Kent f53fbf
+	enc_key2 = NULL;
Ian Kent f53fbf
+
Ian Kent f53fbf
 	if (*qKey == '*' && qKey_len == 1)
Ian Kent f53fbf
 		*qKey = '/';
Ian Kent f53fbf
 	else if (!strcasecmp(class, "nisObject")) {
Ian Kent f53fbf
diff --git a/modules/parse_amd.c b/modules/parse_amd.c
Ian Kent f53fbf
index 9543ced3..ea57270a 100644
Ian Kent f53fbf
--- a/modules/parse_amd.c
Ian Kent f53fbf
+++ b/modules/parse_amd.c
Ian Kent f53fbf
@@ -1879,7 +1879,7 @@ struct amd_entry *make_default_entry(struct autofs_point *ap,
Ian Kent f53fbf
 	 */
Ian Kent f53fbf
 	map_type = conf_amd_get_map_type(ap->path);
Ian Kent f53fbf
 	if (map_type)
Ian Kent f53fbf
-		defaults_entry->map_type = strdup(map_type);
Ian Kent f53fbf
+		defaults_entry->map_type = map_type;
Ian Kent f53fbf
 	/* The list should now be empty .... */
Ian Kent f53fbf
 	free_amd_entry_list(&dflts);
Ian Kent f53fbf
 	return defaults_entry;
Ian Kent f53fbf
@@ -2006,7 +2006,7 @@ static struct amd_entry *get_defaults_entry(struct autofs_point *ap,
Ian Kent f53fbf
 			 */
Ian Kent f53fbf
 			char *map_type = conf_amd_get_map_type(ap->path);
Ian Kent f53fbf
 			if (map_type)
Ian Kent f53fbf
-				entry->map_type = strdup(map_type);
Ian Kent f53fbf
+				entry->map_type = map_type;
Ian Kent f53fbf
 		}
Ian Kent f53fbf
 		free(expand);
Ian Kent f53fbf
 	}
Ian Kent f53fbf
diff --git a/modules/parse_sun.c b/modules/parse_sun.c
Ian Kent f53fbf
index 536a9bc1..88dde0b2 100644
Ian Kent f53fbf
--- a/modules/parse_sun.c
Ian Kent f53fbf
+++ b/modules/parse_sun.c
Ian Kent f53fbf
@@ -443,8 +443,10 @@ int parse_reinit(int argc, const char *const *argv, void **context)
Ian Kent f53fbf
 
Ian Kent f53fbf
 	*new = default_context;
Ian Kent f53fbf
 
Ian Kent f53fbf
-	if (do_init(argc, argv, new))
Ian Kent f53fbf
+	if (do_init(argc, argv, new)) {
Ian Kent f53fbf
+		free(new);
Ian Kent f53fbf
 		return 1;
Ian Kent f53fbf
+	}
Ian Kent f53fbf
 
Ian Kent f53fbf
 	kill_context(ctxt);
Ian Kent f53fbf
 
Ian Kent f53fbf
@@ -1143,6 +1145,9 @@ static int mount_subtree(struct autofs_point *ap, struct mapent *me,
Ian Kent f53fbf
 			const char *root;
Ian Kent f53fbf
 			int ro_len;
Ian Kent f53fbf
 
Ian Kent f53fbf
+			myoptions = NULL;
Ian Kent f53fbf
+			ro_loc = NULL;
Ian Kent f53fbf
+
Ian Kent f53fbf
 			rv = parse_mapent(ro->mapent,
Ian Kent f53fbf
 				options, &myoptions, &ro_loc, ap->logopt);
Ian Kent f53fbf
 			if (!rv) {
Ian Kent f53fbf
@@ -1524,6 +1529,9 @@ dont_expand:
Ian Kent f53fbf
 			p += l;
Ian Kent f53fbf
 			p = skipspace(p);
Ian Kent f53fbf
 
Ian Kent f53fbf
+			myoptions = NULL;
Ian Kent f53fbf
+			loc = NULL;
Ian Kent f53fbf
+
Ian Kent f53fbf
 			l = parse_mapent(p, options, &myoptions, &loc, ap->logopt);
Ian Kent f53fbf
 			if (!l) {
Ian Kent f53fbf
 				cache_delete_offset_list(mc, name);