Avoid calling some free() on WIN32 on memory that may be allocated in
[obnox/wireshark/wip.git] / tap-stats_tree.c
index 1cf1a4fe42e76f27a1958ba3153d59779b8841e2..da4244b0a177872b62004da2d3de1a970fc7c27b 100644 (file)
@@ -1,11 +1,11 @@
 /* tap-stats_tree.c
- * tethereal's tap implememntation of stats_tree
+ * tshark's tap implememntation of stats_tree
  * 2005, Luis E. G. Ontanon
  *
- * $Id$
+ * $Id$
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  * 
  * This program is free software; you can redistribute it and/or
@@ -31,6 +31,8 @@
 #include <stdio.h>
 #include <glib.h>
 #include <epan/stats_tree_priv.h>
+#include <epan/stat_cmd_args.h>
+#include <epan/report_err.h>
 
 /* actually unused */
 struct _st_node_pres {
@@ -67,7 +69,7 @@ static void draw_stats_tree(void *psp) {
        
 }
 
-static void  init_stats_tree(char *optarg) {
+static void  init_stats_tree(const char *optarg,void* userdata _U_) {
        guint8* abbr = stats_tree_get_abbr(optarg);
        GString *error_string;
        stats_tree_cfg *cfg = NULL;
@@ -78,29 +80,33 @@ static void  init_stats_tree(char *optarg) {
 
                if (cfg != NULL) {
                        if (strncmp (optarg, cfg->pr->init_string, strlen(cfg->pr->init_string)) == 0){
-                               st = stats_tree_new(cfg,NULL,((guint8*)optarg)+strlen(cfg->pr->init_string));
+                               st = stats_tree_new(cfg,NULL,(char*)(optarg)+strlen(cfg->pr->init_string));
                        } else {
-                               st->filter=NULL;
+                               report_failure("Wrong stats_tree (%s) found when looking at ->init_string",abbr);
+                               return;
                        }
                } else {
-                       g_error("no such stats_tree (%s) found in stats_tree registry",abbr);
+                       report_failure("no such stats_tree (%s) found in stats_tree registry",abbr);
+                       return;
                }
                
                g_free(abbr);
                
        } else {
-               g_error("could not obtain stats_tree abbr (%s) from optarg '%s'",abbr,optarg);          
+               report_failure("could not obtain stats_tree abbr (%s) from grg '%s'",abbr,optarg);              
+               return;
        }
        
-       error_string = register_tap_listener( st->cfg->tapname,
-                                                                                 st,
-                                                                                 st->filter,
-                                                                                 stats_tree_reset,
-                                                                                 stats_tree_packet,
-                                                                                 draw_stats_tree);
+       error_string = register_tap_listener(st->cfg->tapname,
+                                            st,
+                                            st->filter,
+                                            stats_tree_reset,
+                                            stats_tree_packet,
+                                            draw_stats_tree);
        
        if (error_string) {
-               g_error("stats_tree for: %s failed to attach to the tap: %s",cfg->name,error_string->str);
+               report_failure("stats_tree for: %s failed to attach to the tap: %s",cfg->name,error_string->str);
+               return;
        }
 
        if (cfg->init) cfg->init(st);
@@ -113,7 +119,7 @@ void register_stats_tree_tap (gpointer k _U_, gpointer v, gpointer p _U_) {
        cfg->pr = g_malloc(sizeof(tree_cfg_pres));
        cfg->pr->init_string = g_strdup_printf("%s,tree",cfg->abbr);
 
-       register_ethereal_tap(cfg->pr->init_string, init_stats_tree);
+       register_stat_cmd_arg(cfg->pr->init_string, init_stats_tree, NULL);
        
 }