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

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