Blame SOURCES/autofs-5.1.7-fix-possible-memory-leak-in-mnts_add_amdmount.patch

96dc52
autofs-5.1.7 - fix possible memory leak in mnts_add_amdmount()
96dc52
96dc52
From: Ian Kent <raven@themaw.net>
96dc52
96dc52
Coverity: leaked_storage: Variable "ext_mp" going out of scope leaks
96dc52
	  the storage it points to.
96dc52
96dc52
Same applies to the other duped fields destined for the mnt_list struct.
96dc52
96dc52
Signed-off-by: Ian Kent <raven@themaw.net>
96dc52
---
96dc52
 CHANGELOG    |    1 +
96dc52
 lib/mounts.c |   20 ++++++++++----------
96dc52
 2 files changed, 11 insertions(+), 10 deletions(-)
96dc52
96dc52
diff --git a/CHANGELOG b/CHANGELOG
96dc52
index b797f6dc..2e3b9fd7 100644
96dc52
--- a/CHANGELOG
96dc52
+++ b/CHANGELOG
96dc52
@@ -53,6 +53,7 @@
96dc52
 - add missing free in handle_mounts().
96dc52
 - remove redundant if check.
96dc52
 - fix possible memory leak in master_parse().
96dc52
+- fix possible memory leak in mnts_add_amdmount().
96dc52
 
96dc52
 25/01/2021 autofs-5.1.7
96dc52
 - make bind mounts propagation slave by default.
96dc52
diff --git a/lib/mounts.c b/lib/mounts.c
96dc52
index c8a7bf00..ef69cec1 100644
96dc52
--- a/lib/mounts.c
96dc52
+++ b/lib/mounts.c
96dc52
@@ -1119,16 +1119,16 @@ struct mnt_list *mnts_add_amdmount(struct autofs_point *ap, struct amd_entry *en
96dc52
 
96dc52
 	mnts_hash_mutex_lock();
96dc52
 	this = mnts_get_mount(entry->path);
96dc52
-	if (this) {
96dc52
-		this->ext_mp = ext_mp;
96dc52
-		this->amd_pref = pref;
96dc52
-		this->amd_type = type;
96dc52
-		this->amd_opts = opts;
96dc52
-		this->amd_cache_opts = entry->cache_opts;
96dc52
-		this->flags |= MNTS_AMD_MOUNT;
96dc52
-		if (list_empty(&this->amdmount))
96dc52
-			list_add_tail(&this->amdmount, &ap->amdmounts);
96dc52
-	}
96dc52
+	if (!this)
96dc52
+		goto fail;
96dc52
+	this->ext_mp = ext_mp;
96dc52
+	this->amd_pref = pref;
96dc52
+	this->amd_type = type;
96dc52
+	this->amd_opts = opts;
96dc52
+	this->amd_cache_opts = entry->cache_opts;
96dc52
+	this->flags |= MNTS_AMD_MOUNT;
96dc52
+	if (list_empty(&this->amdmount))
96dc52
+		list_add_tail(&this->amdmount, &ap->amdmounts);
96dc52
 	mnts_hash_mutex_unlock();
96dc52
 
96dc52
 	return this;