[PATCH 1/2] icmap: fix a valgrind errors (pass 1)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Fabio M. Di Nitto" <fdinitto@xxxxxxxxxx>

clean up a lot of allocated blocks at exit.
those changes has no runtime effects, but it makes valgrind
output a bit more useful by dropping over 700 errors/warnings to skip
over every single run.

there are still a few icmap related valgrind errors but those need
some more complex and timeconsuming investigation.

pre patch:

==21844== HEAP SUMMARY:
==21844==     in use at exit: 1,229,321 bytes in 1,516 blocks
==21844==   total heap usage: 7,191 allocs, 5,675 frees, 3,819,853 bytes allocated

==21844== LEAK SUMMARY:
==21844==    definitely lost: 3,617 bytes in 11 blocks
==21844==    indirectly lost: 21,960 bytes in 11 blocks
==21844==      possibly lost: 1,080,101 bytes in 131 blocks
==21844==    still reachable: 123,643 bytes in 1,363 blocks
==21844==         suppressed: 0 bytes in 0 blocks

==21844== ERROR SUMMARY: 136 errors from 136 contexts (suppressed: 0 from 0)

post patch:

==25793== HEAP SUMMARY:
==25793==     in use at exit: 1,185,870 bytes in 808 blocks
==25793==   total heap usage: 9,427 allocs, 8,619 frees, 4,156,841 bytes allocated

==25793== LEAK SUMMARY:
==25793==    definitely lost: 3,697 bytes in 12 blocks
==25793==    indirectly lost: 22,248 bytes in 13 blocks
==25793==      possibly lost: 1,079,655 bytes in 113 blocks
==25793==    still reachable: 80,270 bytes in 670 blocks
==25793==         suppressed: 0 bytes in 0 blocks

==25793== ERROR SUMMARY: 119 errors from 119 contexts (suppressed: 0 from 0)

Signed-off-by: Fabio M. Di Nitto <fdinitto@xxxxxxxxxx>
---
 exec/icmap.c             |   47 ++++++++++++++++++++++++++++++++++++++++++++++
 exec/main.c              |    1 +
 include/corosync/icmap.h |    1 +
 3 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/exec/icmap.c b/exec/icmap.c
index d51a972..2743959 100644
--- a/exec/icmap.c
+++ b/exec/icmap.c
@@ -59,6 +59,7 @@ struct icmap_track {
 	int32_t track_type;
 	icmap_notify_fn_t notify_fn;
 	void *user_data;
+	struct list_head list;
 };
 
 struct icmap_ro_access_item {
@@ -68,6 +69,7 @@ struct icmap_ro_access_item {
 };
 
 DECLARE_LIST_INIT(icmap_ro_access_item_list_head);
+DECLARE_LIST_INIT(icmap_track_list_head);
 
 /*
  * Static functions declarations
@@ -194,6 +196,47 @@ cs_error_t icmap_init(void)
 	return (qb_to_cs_error(err));
 }
 
+static void icmap_set_ro_access_free(void)
+{
+	struct list_head *iter = icmap_ro_access_item_list_head.next;
+	struct icmap_ro_access_item *icmap_ro_ai;
+
+	while (iter != &icmap_ro_access_item_list_head) {
+		icmap_ro_ai = list_entry(iter, struct icmap_ro_access_item, list);
+		list_del(&icmap_ro_ai->list);
+		free(icmap_ro_ai->key_name);
+		free(icmap_ro_ai);
+		iter = icmap_ro_access_item_list_head.next;
+	}
+}
+
+static void icmap_del_all_track(void)
+{
+	struct list_head *iter = icmap_track_list_head.next;
+	struct icmap_track *icmap_track;
+
+	while (iter != &icmap_track_list_head) {
+		icmap_track = list_entry(iter, struct icmap_track, list);
+		icmap_track_delete(icmap_track);
+		iter = icmap_track_list_head.next;
+	}
+}
+
+void icmap_fini(void)
+{
+	icmap_del_all_track();
+	/*
+	 * catch 22 warning:
+	 * We need to drop this notify but we can't because it calls icmap_map_free_cb
+	 * while destroying the tree to free icmap_item(s).
+	 * -> qb_map_notify_del_2(icmap_map, NULL, icmap_map_free_cb, QB_MAP_NOTIFY_FREE, NULL);
+	 * and we cannot call it after map_destroy. joy! :)
+	 */
+	qb_map_destroy(icmap_map);
+	icmap_set_ro_access_free();
+	return;
+}
+
 static int icmap_is_valid_name_char(char c)
 {
 	return ((c >= 'a' && c <= 'z') ||
@@ -864,6 +907,9 @@ cs_error_t icmap_track_add(
 		return (qb_to_cs_error(err));
 	}
 
+	list_init(&(*icmap_track)->list);
+	list_add (&(*icmap_track)->list, &icmap_track_list_head);
+
 	return (CS_OK);
 }
 
@@ -876,6 +922,7 @@ cs_error_t icmap_track_delete(icmap_track_t icmap_track)
 		return (qb_to_cs_error(err));
 	}
 
+	list_del(&icmap_track->list);
 	free(icmap_track->key_name);
 	free(icmap_track);
 
diff --git a/exec/main.c b/exec/main.c
index 2f3d242..a125bbd 100644
--- a/exec/main.c
+++ b/exec/main.c
@@ -192,6 +192,7 @@ static void unlink_all_completed (void)
 {
 	api->timer_delete (corosync_stats_timer_handle);
 	qb_loop_stop (corosync_poll_handle);
+	icmap_fini();
 }
 
 void corosync_shutdown_request (void)
diff --git a/include/corosync/icmap.h b/include/corosync/icmap.h
index 80aac25..4063771 100644
--- a/include/corosync/icmap.h
+++ b/include/corosync/icmap.h
@@ -120,6 +120,7 @@ typedef struct icmap_track *icmap_track_t;
  * Initialize icmap
  */
 extern cs_error_t icmap_init(void);
+extern void icmap_fini(void);
 
 /*
  * Store value with value_len length and type as key_name name in icmap.
-- 
1.7.7.6

_______________________________________________
discuss mailing list
discuss@xxxxxxxxxxxx
http://lists.corosync.org/mailman/listinfo/discuss


[Index of Archives]     [Linux Clusters]     [Corosync Project]     [Linux USB Devel]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Linux Kernel]     [Linux SCSI]     [X.Org]

  Powered by Linux