tibbs / rpms / iftop

Forked from rpms/iftop 6 years ago
Clone
b6e89b5
Patch by Michal Hlavinka <mhlavink@redhat.com> for iftop >= 0.17, which
b6e89b5
fixes a problem in the stringmap implementation. When removing some node
b6e89b5
from the tree, node itself is deallocated, but parent's pointer remains
b6e89b5
set. This results to pointer with free(ed) memory. Further details can be
b6e89b5
found at: https://bugzilla.redhat.com/show_bug.cgi?id=601087
b6e89b5
b6e89b5
--- iftop-0.17/stringmap.c		2003-11-07 00:37:20.000000000 +0100
b6e89b5
+++ iftop-0.17/stringmap.c.fixtree	2010-07-09 23:53:18.000000000 +0200
b6e89b5
@@ -34,6 +34,10 @@
b6e89b5
     if (!S) return;
b6e89b5
     if (S->l) stringmap_delete(S->l);
b6e89b5
     if (S->g) stringmap_delete(S->g);
b6e89b5
+    if (S->p) {
b6e89b5
+        if (S->p->l == S) S->p->l = NULL;
b6e89b5
+        else S->p->g = NULL;
b6e89b5
+    }
b6e89b5
 
b6e89b5
     xfree(S->key);
b6e89b5
     xfree(S);
b6e89b5
@@ -46,6 +50,10 @@
b6e89b5
     if (!S) return;
b6e89b5
     if (S->l) stringmap_delete_free(S->l);
b6e89b5
     if (S->g) stringmap_delete_free(S->g);
b6e89b5
+    if (S->p) {
b6e89b5
+        if (S->p->l == S) S->p->l = NULL;
b6e89b5
+        else S->p->g = NULL;
b6e89b5
+    }
b6e89b5
 
b6e89b5
     xfree(S->key);
b6e89b5
     xfree(S->d.v);
b6e89b5
@@ -75,6 +83,7 @@
b6e89b5
                     if (!(S2->l = stringmap_new())) return NULL;
b6e89b5
                     S2->l->key = xstrdup(k);
b6e89b5
                     S2->l->d   = d;
b6e89b5
+                    S2->l->p   = S2;
b6e89b5
                     return NULL;
b6e89b5
                 }
b6e89b5
             } else if (i > 0) {
b6e89b5
@@ -83,6 +92,7 @@
b6e89b5
                     if (!(S2->g = stringmap_new())) return NULL;
b6e89b5
                     S2->g->key = xstrdup(k);
b6e89b5
                     S2->g->d   = d;
b6e89b5
+                    S2->g->p   = S2;
b6e89b5
                     return NULL;
b6e89b5
                 }
b6e89b5
             }
b6e89b5
--- iftop-0.17/stringmap.h		2003-10-19 08:44:33.000000000 +0200
b6e89b5
+++ iftop-0.17/stringmap.h.fixtree	2010-07-09 23:53:37.000000000 +0200
b6e89b5
@@ -16,7 +16,7 @@
b6e89b5
 typedef struct _stringmap {
b6e89b5
     char *key;
b6e89b5
     item d;
b6e89b5
-    struct _stringmap *l, *g;
b6e89b5
+    struct _stringmap *l, *g, *p;
b6e89b5
 } *stringmap;
b6e89b5
 
b6e89b5
 stringmap stringmap_new(void);