Blame SOURCES/autofs-5.1.0-fix-memory-leak-in-get_exports.patch

6bbd11
autofs-5.1.0 - fix memory leak in get_exports()
6bbd11
6bbd11
From: Ian Kent <ikent@redhat.com>
6bbd11
6bbd11
In modules/lookup_hosts.c:get_exports() looping over the returned list of
6bbd11
exports uses the pointer that contains the list. The pointer is updated
6bbd11
in the process of creating the exports multi-mount so a pointer to the
6bbd11
returned list is no longer available to be freed when done.
6bbd11
---
6bbd11
 CHANGELOG              |    1 +
6bbd11
 modules/lookup_hosts.c |   17 +++++++++--------
6bbd11
 2 files changed, 10 insertions(+), 8 deletions(-)
6bbd11
6bbd11
--- autofs-5.0.7.orig/CHANGELOG
6bbd11
+++ autofs-5.0.7/CHANGELOG
6bbd11
@@ -149,6 +149,7 @@
6bbd11
 - force disable browse mode for amd format maps.
6bbd11
 - fix hosts map options check in lookup_amd_instance().
6bbd11
 - fix memory leak in create_client().
6bbd11
+- fix memory leak in get_exports().
6bbd11
 
6bbd11
 25/07/2012 autofs-5.0.7
6bbd11
 =======================
6bbd11
--- autofs-5.0.7.orig/modules/lookup_hosts.c
6bbd11
+++ autofs-5.0.7/modules/lookup_hosts.c
6bbd11
@@ -82,18 +82,19 @@ static char *get_exports(struct autofs_p
6bbd11
 {
6bbd11
 	char buf[MAX_ERR_BUF];
6bbd11
 	char *mapent;
6bbd11
-	exports exp;
6bbd11
+	exports exp, this;
6bbd11
 
6bbd11
 	debug(ap->logopt, MODPREFIX "fetchng export list for %s", host);
6bbd11
 
6bbd11
 	exp = rpc_get_exports(host, 10, 0, RPC_CLOSE_NOLINGER);
6bbd11
 
6bbd11
 	mapent = NULL;
6bbd11
-	while (exp) {
6bbd11
+	this = exp;
6bbd11
+	while (this) {
6bbd11
 		if (mapent) {
6bbd11
 			int len = strlen(mapent) + 1;
6bbd11
 
6bbd11
-			len += strlen(host) + 2*(strlen(exp->ex_dir) + 2) + 3;
6bbd11
+			len += strlen(host) + 2*(strlen(this->ex_dir) + 2) + 3;
6bbd11
 			mapent = realloc(mapent, len);
6bbd11
 			if (!mapent) {
6bbd11
 				char *estr;
6bbd11
@@ -103,10 +104,10 @@ static char *get_exports(struct autofs_p
6bbd11
 				return NULL;
6bbd11
 			}
6bbd11
 			strcat(mapent, " \"");
6bbd11
-			strcat(mapent, exp->ex_dir);
6bbd11
+			strcat(mapent, this->ex_dir);
6bbd11
 			strcat(mapent, "\"");
6bbd11
 		} else {
6bbd11
-			int len = 2*(strlen(exp->ex_dir) + 2) + strlen(host) + 3;
6bbd11
+			int len = 2*(strlen(this->ex_dir) + 2) + strlen(host) + 3;
6bbd11
 
6bbd11
 			mapent = malloc(len);
6bbd11
 			if (!mapent) {
6bbd11
@@ -117,16 +118,16 @@ static char *get_exports(struct autofs_p
6bbd11
 				return NULL;
6bbd11
 			}
6bbd11
 			strcpy(mapent, "\"");
6bbd11
-			strcat(mapent, exp->ex_dir);
6bbd11
+			strcat(mapent, this->ex_dir);
6bbd11
 			strcat(mapent, "\"");
6bbd11
 		}
6bbd11
 		strcat(mapent, " \"");
6bbd11
 		strcat(mapent, host);
6bbd11
 		strcat(mapent, ":");
6bbd11
-		strcat(mapent, exp->ex_dir);
6bbd11
+		strcat(mapent, this->ex_dir);
6bbd11
 		strcat(mapent, "\"");
6bbd11
 
6bbd11
-		exp = exp->ex_next;
6bbd11
+		this = this->ex_next;
6bbd11
 	}
6bbd11
 	rpc_exports_free(exp);
6bbd11