[libgtop] Oops, fix segfault in linux/proc_map.



commit 2458096acf095c62b4e27005ed5fbe07b03f4fb5
Author: Benoît Dejean <benoit placenet org>
Date:   Sun May 3 19:41:22 2009 +0200

    Oops, fix segfault in linux/proc_map.
    I've commited the wrong patch, got lost in the svn->git change.
---
 NEWS                    |    5 +++++
 configure.in            |    2 +-
 sysdeps/linux/procmap.c |   13 ++++++++-----
 3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/NEWS b/NEWS
index 9aacc80..221989c 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
+3 May 2009: Overview of changes in 2.27.2
+=========================================
+* linux:
+  - glibtop_get_proc_map: oops, fixed segfault.
+
 3 May 2009: Overview of changes in 2.27.1
 =========================================
 * linux:
diff --git a/configure.in b/configure.in
index 73f7316..9cd8d53 100644
--- a/configure.in
+++ b/configure.in
@@ -4,7 +4,7 @@ dnl
 
 m4_define([libgtop_major_version], [2])
 m4_define([libgtop_minor_version], [27])
-m4_define([libgtop_micro_version], [1])
+m4_define([libgtop_micro_version], [2])
 m4_define([libgtop_version], [libgtop_major_version.libgtop_minor_version.libgtop_micro_version])
 
 dnl  increment if the interface has additions, changes, removals.
diff --git a/sysdeps/linux/procmap.c b/sysdeps/linux/procmap.c
index 31dd9b1..d7f0e72 100644
--- a/sysdeps/linux/procmap.c
+++ b/sysdeps/linux/procmap.c
@@ -192,10 +192,10 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf,	pid_t pid)
 	  It's the average number of entry per process on my laptop
 	*/
 
-	size_t added = 0;
+	size_t added = 0, entry_list_capacity = 100;
 	GArray *entry_list = g_array_sized_new(FALSE, FALSE,
 					       sizeof(glibtop_map_entry),
-					       100);
+					       entry_list_capacity);
 	FILE *maps;
 	const char *filename;
 	gboolean has_smaps;
@@ -271,8 +271,11 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf,	pid_t pid)
 		  element.
 		*/
 
-		if (G_UNLIKELY(added >= entry_list->len)) {
-			g_array_set_size(entry_list, 2 * entry_list->len);
+		g_debug("added = %d len = %d\n", (int)added, (int)entry_list_capacity);
+
+		if (G_UNLIKELY(added >= entry_list_capacity)) {
+			entry_list_capacity *= 2;
+			g_array_set_size(entry_list, entry_list_capacity);
 		}
 
 		entry = &g_array_index(entry_list, glibtop_map_entry, added++);
@@ -308,7 +311,7 @@ eof:
 
 	buf->flags = _glibtop_sysdeps_proc_map;
 
-	buf->number = entry_list->len;
+	buf->number = added;
 	buf->size = sizeof (glibtop_map_entry);
 	buf->total = buf->number * buf->size;
 



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