aboutsummaryrefslogtreecommitdiffstats
path: root/tap-stats_tree.c
diff options
context:
space:
mode:
authorLuis Ontanon <luis.ontanon@gmail.com>2005-03-20 00:19:15 +0000
committerLuis Ontanon <luis.ontanon@gmail.com>2005-03-20 00:19:15 +0000
commit9e9a65836965f44d9752b41ea0c9ee03ae5749fa (patch)
treee86663ae32c8fab0aa2dc50c67e9d5f8148ecff9 /tap-stats_tree.c
parent4012e774fdf10ceafe7d6925bba54c88edff545c (diff)
There was a design flaw that caused a crash on windows and
left uninitialized successive copies of the stats tree. Split the stats_tree data in two different structs one for data that's always needed and it's not going to change at every run and another for each run of the tap. svn path=/trunk/; revision=13816
Diffstat (limited to 'tap-stats_tree.c')
-rw-r--r--tap-stats_tree.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/tap-stats_tree.c b/tap-stats_tree.c
index 2c85abcd92..4c0f3a1925 100644
--- a/tap-stats_tree.c
+++ b/tap-stats_tree.c
@@ -37,8 +37,11 @@ struct _st_node_pres {
void* dummy;
};
-
struct _tree_pres {
+ void* dummy;
+};
+
+struct _tree_cfg_pres {
guint8* init_string;
};
@@ -50,7 +53,7 @@ static void draw_stats_tree(void *psp) {
s = g_string_new("\n===================================================================\n");
fmt = g_strdup_printf(" %%s%%-%us%%12s\t%%12s\t%%12s\n",stats_branch_max_name_len(&st->root,0));
- g_string_sprintfa(s,fmt,"",st->name,"value","rate","percent");
+ g_string_sprintfa(s,fmt,"",st->cfg->name,"value","rate","percent");
g_free(fmt);
g_string_sprintfa(s,"-------------------------------------------------------------------\n");
@@ -67,14 +70,15 @@ static void draw_stats_tree(void *psp) {
static void init_stats_tree(char *optarg) {
guint8* abbr = get_st_abbr(optarg);
GString *error_string;
- stats_tree *st = NULL;
-
+ stats_tree_cfg *cfg = NULL;
+ stats_tree* st = NULL;
+
if (abbr) {
- st = get_stats_tree_by_abbr(abbr);
-
- if (st != NULL) {
- if (strncmp (optarg, st->pr->init_string, strlen(st->pr->init_string)) == 0){
- st->filter=((guint8*)optarg)+strlen(st->pr->init_string);
+ cfg = get_stats_tree_by_abbr(abbr);
+
+ if (cfg != NULL) {
+ if (strncmp (optarg, cfg->pr->init_string, strlen(cfg->pr->init_string)) == 0){
+ st = new_stats_tree(cfg,NULL,((guint8*)optarg)+strlen(cfg->pr->init_string));
} else {
st->filter=NULL;
}
@@ -88,7 +92,7 @@ static void init_stats_tree(char *optarg) {
g_error("could not obtain stats_tree abbr (%s) from optarg '%s'",abbr,optarg);
}
- error_string = register_tap_listener( st->tapname,
+ error_string = register_tap_listener( st->cfg->tapname,
st,
st->filter,
reset_stats_tree,
@@ -96,28 +100,32 @@ static void init_stats_tree(char *optarg) {
draw_stats_tree);
if (error_string) {
- g_error("stats_tree for: %s failed to attach to the tap: %s",st->name,error_string->str);
+ g_error("stats_tree for: %s failed to attach to the tap: %s",cfg->name,error_string->str);
}
- if (st->init) st->init(st);
+ if (cfg->init) cfg->init(st);
}
void register_stats_tree_tap (gpointer k _U_, gpointer v, gpointer p _U_) {
- stats_tree* st = v;
+ stats_tree_cfg* cfg = v;
- st->pr = g_malloc(sizeof(tree_pres));
- st->pr->init_string = g_strdup_printf("%s,tree",st->abbr);
+ cfg->pr = g_malloc(sizeof(tree_cfg_pres));
+ cfg->pr->init_string = g_strdup_printf("%s,tree",cfg->abbr);
- register_ethereal_tap(st->pr->init_string, init_stats_tree);
+ register_ethereal_tap(cfg->pr->init_string, init_stats_tree);
}
+static void free_tree_presentation(stats_tree* st) {
+ g_free(st->pr);
+}
+
void
register_tap_listener_stats_tree_stat(void)
{
stats_tree_presentation(register_stats_tree_tap,
NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL);
+ free_tree_presentation, NULL, NULL, NULL);
}