Skip to contentSkip to conversation

Set of patches fixing memory leaks.

PATCH New Konrad Rzeszutek 1 participant 6 messages Dec 16, 2008 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Set of patches fixing memory leaks.

Here are some patches for some of the memory leaks I've observed when using multipathd with large amounts of LUNs and when heavily re-adding/deleting multipath device mapper maps.

Most of the fixes are faily simple, but the overall effect is that multipathd shrinks from 1.3GB (with 2000 LUNs) down to 60MB.

 libmultipath/configure.c |    5 +++++
 libmultipath/devmapper.c |   18 ++++++++++--------
 libmultipath/memory.c    |    5 ++---
 multipathd/main.c        |    3 +++
 4 files changed, 20 insertions(+), 11 deletions(-)
#1 lore raw

PATCH 1/1 Substantial memory leak when large amount of LUNs are present.

From: Konrad Rzeszutek <[email protected]>

dm_get_name() was creating a vector, populating it with multipaths, then only deleting the vector itself, which leaked all of the multipaths. If the number of LUNs (ie. multipaths) was large then the leak was equally large.

---
 libmultipath/devmapper.c |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)
libmultipath/devmapper.c +9 -7
index 70e10c2..a021e44 100644
@@ -764,7 +764,7 @@ dm_get_name(char *uuid, char *name)
 {
 	vector vec;
 	struct multipath *mpp;
-	int i;
+	int i, rc = 0;
 
 	vec = vector_alloc();
 
@@ -772,20 +772,22 @@ dm_get_name(char *uuid, char *name)
 		return 0;
 
 	if (dm_get_maps(vec)) {
-		vector_free(vec);
-		return 0;
+		goto out;
 	}
 
 	vector_foreach_slot(vec, mpp, i) {
 		if (!strcmp(uuid, mpp->wwid)) {
-			vector_free(vec);
 			strcpy(name, mpp->alias);
-			return 1;
+			rc=1;
+			break;
 		}
 	}
-
+out:
+	vector_foreach_slot(vec, mpp, i) {
+		free_multipath(mpp, KEEP_PATHS);
+	}
 	vector_free(vec);
-	return 0;
+	return rc;
 }
 
 int
Signature · 1 line
1.5.4.1
#2 lore raw

PATCH 1/1 Memory leak when deleting and re-adding device-mapper entries.

From: Konrad Rzeszutek <[email protected]>

If we remove a map (with configuration details specified in the multipath.conf file) and later re-add it, the pointer to the config is over-written without first de-allocating the values.

---
 libmultipath/configure.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
libmultipath/configure.c +5 -0
index 285a8a2..83ee0ae 100644
@@ -50,6 +50,11 @@ setup_map (struct multipath * mpp)
 	}
 
 	/*
+	 * free features, selector, and hwhandler properties if they are being reused
+	 */
+	free_multipath_attributes(mpp);
+
+	/*
 	 * properties selectors
 	 */
 	select_pgfailback(mpp);
Signature · 1 line
1.5.4.1
#3 lore raw

PATCH 1/1 The internal debug memory leak printout has output jumbled.

From: Konrad Rzeszutek <[email protected]>

When using the internal memory leak the function that call realloc get a confused output. The fix puts the list of operation in the right order.

---
 libmultipath/memory.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
libmultipath/memory.c +2 -3
index 71dfe40..bd6ae5e 100644
@@ -459,9 +459,8 @@ dbg_realloc(void *buffer, unsigned long size, char *file, char *function,
 	if (debug & 1)
 		printf("realloc [%3d:%3d] %p, %4ld %s %d %s -> %p %4ld %s %d %s\n",
 		       i, number_alloc_list, alloc_list[i].ptr,
-		       alloc_list[i].size, file, line, function, buf, size,
-		       alloc_list[i].file, alloc_list[i].line,
-		       alloc_list[i].func);
+		       alloc_list[i].size, alloc_list[i].file, alloc_list[i].line, alloc_list[i].func,
+		       buf, size, file, line, function);
 
 	alloc_list[i].ptr = buf;
 	alloc_list[i].size = size;
Signature · 1 line
1.5.4.1
#4 lore raw

PATCH 1/1 Memory leak in ev_add_map.

From: Konrad Rzeszutek <[email protected]>

When using dm_mapname it makes a strdup of the returned value. We use the dm_mapname return value (alias) in our function but neglected to free it at the exit points.

---
 multipathd/main.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
multipathd/main.c +3 -0
index 30dba5b..e8a2660 100644
@@ -243,6 +243,7 @@ ev_add_map (struct sysfs_device * dev, struct vectors * vecs)
 
 	if (map_present && dm_type(alias, TGT_MPATH) <= 0) {
 		condlog(4, "%s: not a multipath map", alias);
+		FREE(alias);
 		return 0;
 	}
 
@@ -256,6 +257,7 @@ ev_add_map (struct sysfs_device * dev, struct vectors * vecs)
 		 */
 		condlog(0, "%s: devmap already registered",
 			dev->kernel);
+		FREE(alias);
 		return 0;
 	}
 
@@ -280,6 +282,7 @@ ev_add_map (struct sysfs_device * dev, struct vectors * vecs)
 		condlog(0, "%s: uev_add_map %s failed", alias, dev->kernel);
 
 	FREE(refwwid);
+	FREE(alias);
 	return r;
 }
 
Signature · 1 line
1.5.4.1
#5 lore raw

PATCH 1/1 Need to use FREE macro instead of free.

From: Konrad Rzeszutek <[email protected]>

When using the internal memory leak checker it is imperative that all free use the FREE macro. Otherwise accounting errors show up.

---
 libmultipath/devmapper.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
libmultipath/devmapper.c +1 -1
index a021e44..bcbeb28 100644
@@ -211,7 +211,7 @@ dm_addmap (int task, const char *name, const char *target,
 
 	freeout:
 	if (prefixed_uuid)
-		free(prefixed_uuid);
+		FREE(prefixed_uuid);
 
 	addout:
 	dm_task_destroy (dmt);
Signature · 1 line
1.5.4.1