Blame SOURCES/0003-fix-segfault-in-adding-interface.patch

5f40dd
From 690663d07f29789c1ba2260e59c4f71b8721dea6 Mon Sep 17 00:00:00 2001
5f40dd
From: Vitezslav Samel <vitezslav@samel.cz>
5f40dd
Date: Thu, 17 Apr 2014 14:24:23 +0200
5f40dd
Subject: [PATCH 001/111] bugfix: positionptr(): properly allocate newly
5f40dd
 created interfaces
5f40dd
5f40dd
When creating new entry in interface list (for interface created when
5f40dd
ifstats() already running) we must allocate/init the rate too.
5f40dd
5f40dd
Fix this bug by creating new function alloc_iflist_entry() and use it
5f40dd
where appropriate.
5f40dd
5f40dd
Signed-off-by: Vitezslav Samel <vitezslav@samel.cz>
5f40dd
Signed-off-by: Nikola Pajkovsky <n.pajkovsky@gmail.com>
5f40dd
---
5f40dd
 src/ifstats.c | 16 ++++++++++++----
5f40dd
 1 file changed, 12 insertions(+), 4 deletions(-)
5f40dd
5f40dd
diff --git a/src/ifstats.c b/src/ifstats.c
5f40dd
index 2eb51b6..2a5bba4 100644
5f40dd
--- a/src/ifstats.c
5f40dd
+++ b/src/ifstats.c
5f40dd
@@ -126,6 +126,15 @@ static int ifinlist(struct iflist *list, char *ifname)
5f40dd
 	return result;
5f40dd
 }
5f40dd
 
5f40dd
+static struct iflist *alloc_iflist_entry(void)
5f40dd
+{
5f40dd
+	struct iflist *tmp = xmallocz(sizeof(struct iflist));
5f40dd
+
5f40dd
+	rate_alloc(&tmp->rate, 5);
5f40dd
+
5f40dd
+	return tmp;
5f40dd
+}
5f40dd
+
5f40dd
 /*
5f40dd
  * Initialize the list of interfaces.  This linked list is used in the
5f40dd
  * selection boxes as well as in the general interface statistics screen.
5f40dd
@@ -171,10 +180,9 @@ static void initiflist(struct iflist **list)
5f40dd
 		 * At this point, the interface is now sure to be up and running.
5f40dd
 		 */
5f40dd
 
5f40dd
-		struct iflist *itmp = xmallocz(sizeof(struct iflist));
5f40dd
-		strcpy(itmp->ifname, ifname);
5f40dd
+		struct iflist *itmp = alloc_iflist_entry();
5f40dd
 		itmp->ifindex = ifindex;
5f40dd
-		rate_alloc(&itmp->rate, 5);
5f40dd
+		strcpy(itmp->ifname, ifname);
5f40dd
 
5f40dd
 		/* make the linked list sorted by ifindex */
5f40dd
 		struct iflist *cur = *list, *last = NULL;
5f40dd
@@ -211,7 +219,7 @@ static struct iflist *positionptr(struct iflist *iflist, const int ifindex)
5f40dd
 	}
5f40dd
 	/* no interface was found, try to create new one */
5f40dd
 	if (ptmp == NULL) {
5f40dd
-		struct iflist *itmp = xmallocz(sizeof(struct iflist));
5f40dd
+		struct iflist *itmp = alloc_iflist_entry();
5f40dd
 		itmp->ifindex = ifindex;
5f40dd
 		itmp->index = last->index + 1;
5f40dd
 		int r = dev_get_ifname(ifindex, itmp->ifname);
5f40dd
-- 
5f40dd
2.5.5
5f40dd