Sophie

Sophie

distrib > Fedora > 13 > i386 > media > updates-src > by-pkgid > d3da47e473396ce88b22c4103ac14adc > files > 4

iftop-0.17-12.fc13.src.rpm

Patch by Michal Hlavinka <mhlavink@redhat.com> for iftop >= 0.17, which
fixes a problem in the stringmap implementation. When removing some node
from the tree, node itself is deallocated, but parent's pointer remains
set. This results to pointer with free(ed) memory. Further details can be
found at: https://bugzilla.redhat.com/show_bug.cgi?id=601087

--- iftop-0.17/stringmap.c		2003-11-07 00:37:20.000000000 +0100
+++ iftop-0.17/stringmap.c.fixtree	2010-07-09 23:53:18.000000000 +0200
@@ -34,6 +34,10 @@
     if (!S) return;
     if (S->l) stringmap_delete(S->l);
     if (S->g) stringmap_delete(S->g);
+    if (S->p) {
+        if (S->p->l == S) S->p->l = NULL;
+        else S->p->g = NULL;
+    }
 
     xfree(S->key);
     xfree(S);
@@ -46,6 +50,10 @@
     if (!S) return;
     if (S->l) stringmap_delete_free(S->l);
     if (S->g) stringmap_delete_free(S->g);
+    if (S->p) {
+        if (S->p->l == S) S->p->l = NULL;
+        else S->p->g = NULL;
+    }
 
     xfree(S->key);
     xfree(S->d.v);
@@ -75,6 +83,7 @@
                     if (!(S2->l = stringmap_new())) return NULL;
                     S2->l->key = xstrdup(k);
                     S2->l->d   = d;
+                    S2->l->p   = S2;
                     return NULL;
                 }
             } else if (i > 0) {
@@ -83,6 +92,7 @@
                     if (!(S2->g = stringmap_new())) return NULL;
                     S2->g->key = xstrdup(k);
                     S2->g->d   = d;
+                    S2->g->p   = S2;
                     return NULL;
                 }
             }
--- iftop-0.17/stringmap.h		2003-10-19 08:44:33.000000000 +0200
+++ iftop-0.17/stringmap.h.fixtree	2010-07-09 23:53:37.000000000 +0200
@@ -16,7 +16,7 @@
 typedef struct _stringmap {
     char *key;
     item d;
-    struct _stringmap *l, *g;
+    struct _stringmap *l, *g, *p;
 } *stringmap;
 
 stringmap stringmap_new(void);