package iftop tags 425488 + patch thanks I have located the cause of this problem. The original authors did implement a binary tree to store configuration settings. They failed miserably in handling the case of multiple nodes of identical key value.
The patch is based on the assumption: Each configuration option need only deposit a single value. In case of multiple assignments, the last value provided will be kept for runtime behaviour. The actual code gives support for this assumption. The lesson to learn is that one should use the simplest possible data structure, not any deep and undigested notions. Best regards, Mats Erik Andersson, fil. dr
diff -Naurp iftop-0.17.debian/cfgfile.c iftop-0.17/cfgfile.c
--- iftop-0.17.debian/cfgfile.c
+++ iftop-0.17/cfgfile.c
@@ -230,8 +230,15 @@ void config_set_string(const char *direc
stringmap S;
S = stringmap_find(config, directive);
- if (S) stringmap_delete_free(S);
- stringmap_insert(config, directive, item_ptr(xstrdup(s)));
+ if (S) {
+ /* Replace any already stored string value.
+ * The node can simply not be deleted straight off,
+ * due to possible presence of leafs on either side. */
+ if (S->d.v)
+ xfree(S->d.v);
+ S->d.v = xstrdup(s);
+ } else
+ stringmap_insert(config, directive, item_ptr(xstrdup(s)));
}
int read_config(char *file, int whinge_on_error) {
diff -Naurp iftop-0.17.debian/stringmap.c iftop-0.17/stringmap.c
--- iftop-0.17.debian/stringmap.c
+++ iftop-0.17/stringmap.c
@@ -53,11 +53,11 @@ void stringmap_delete_free(stringmap S)
}
/* stringmap_insert:
- * Insert into S an item having key k and value d. Returns an existing key
- * or NULL if it was inserted.
+ * Insert into S an item having key k and value d. Returns a pointer to
+ * the existing item value, or NULL if a new item was created.
*/
item *stringmap_insert(stringmap S, const char *k, const item d) {
- if (!S) return 0;
+ if (!S) return NULL;
if (S->key == NULL) {
S->key = xstrdup(k);
S->d = d;
signature.asc
Description: Digital signature

