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

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