Reassemble: fix premature free
[metze/wireshark/wip.git] / tfshark.c
index 7b8febc1accf2e34a64a4a7a7070bd93720c1e2f..292158ee6a47990c1c557edee63506954992fa2f 100644 (file)
--- a/tfshark.c
+++ b/tfshark.c
 #include <epan/addr_resolv.h>
 #include "ui/util.h"
 #include "ui/decode_as_utils.h"
+#include "ui/dissect_opts.h"
 #include "register.h"
 #include <epan/epan_dissect.h>
 #include <epan/tap.h>
 #include <epan/stat_tap_ui.h>
 #include <epan/ex-opt.h>
 
-#if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
-#include <epan/asn1.h>
-#include <epan/dissectors/packet-kerberos.h>
+#ifdef HAVE_EXTCAP
+#include "extcap.h"
 #endif
 
 #include <wiretap/wtap-int.h>
@@ -102,8 +102,6 @@ static frame_data prev_dis_frame;
 static frame_data *prev_cap;
 static frame_data prev_cap_frame;
 
-static const char* prev_display_dissector_name = NULL;
-
 static gboolean perform_two_pass_analysis;
 
 /*
@@ -418,6 +416,8 @@ main(int argc, char *argv[])
          "\n"
          "%s",
       get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str);
+  g_string_free(comp_info_str, TRUE);
+  g_string_free(runtime_info_str, TRUE);
 
   /*
    * In order to have the -X opts assigned before the wslua machine starts
@@ -507,7 +507,7 @@ main(int argc, char *argv[])
 
   /* Scan for plugins.  This does *not* call their registration routines;
      that's done later. */
-  scan_plugins();
+  scan_plugins(REPORT_LOAD_FAILURE);
 
 #endif
 
@@ -684,15 +684,6 @@ main(int argc, char *argv[])
     case 'C':
       /* already processed; just ignore it now */
       break;
-    case 'd':        /* Decode as rule */
-      if (!decode_as_command_option(optarg))
-        return 1;
-      break;
-#if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
-    case 'K':        /* Kerberos keytab file */
-      read_keytab_file(optarg);
-      break;
-#endif
     case 'e':
       /* Field entry */
       output_fields_add(output_fields, optarg);
@@ -763,42 +754,6 @@ main(int argc, char *argv[])
     case 'S':        /* Set the line Separator to be printed between packets */
       separator = g_strdup(optarg);
       break;
-    case 't':        /* Time stamp type */
-      if (strcmp(optarg, "r") == 0)
-        timestamp_set_type(TS_RELATIVE);
-      else if (strcmp(optarg, "a") == 0)
-        timestamp_set_type(TS_ABSOLUTE);
-      else if (strcmp(optarg, "ad") == 0)
-        timestamp_set_type(TS_ABSOLUTE_WITH_YMD);
-      else if (strcmp(optarg, "adoy") == 0)
-        timestamp_set_type(TS_ABSOLUTE_WITH_YDOY);
-      else if (strcmp(optarg, "d") == 0)
-        timestamp_set_type(TS_DELTA);
-      else if (strcmp(optarg, "dd") == 0)
-        timestamp_set_type(TS_DELTA_DIS);
-      else if (strcmp(optarg, "e") == 0)
-        timestamp_set_type(TS_EPOCH);
-      else if (strcmp(optarg, "u") == 0)
-        timestamp_set_type(TS_UTC);
-      else if (strcmp(optarg, "ud") == 0)
-        timestamp_set_type(TS_UTC_WITH_YMD);
-      else if (strcmp(optarg, "udoy") == 0)
-        timestamp_set_type(TS_UTC_WITH_YDOY);
-      else {
-        cmdarg_err("Invalid time stamp type \"%s\"; it must be one of:", optarg);
-        cmdarg_err_cont("\t\"a\"    for absolute\n"
-                        "\t\"ad\"   for absolute with YYYY-MM-DD date\n"
-                        "\t\"adoy\" for absolute with YYYY/DOY date\n"
-                        "\t\"d\"    for delta\n"
-                        "\t\"dd\"   for delta displayed\n"
-                        "\t\"e\"    for epoch\n"
-                        "\t\"r\"    for relative\n"
-                        "\t\"u\"    for absolute UTC\n"
-                        "\t\"ud\"   for absolute UTC with YYYY-MM-DD date\n"
-                        "\t\"udoy\" for absolute UTC with YYYY/DOY date");
-        return 1;
-      }
-      break;
     case 'T':        /* printing Type */
       if (strcmp(optarg, "text") == 0) {
         output_action = WRITE_TEXT;
@@ -839,20 +794,9 @@ main(int argc, char *argv[])
         return 1;
       }
       break;
-    case 'u':        /* Seconds type */
-      if (strcmp(optarg, "s") == 0)
-        timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
-      else if (strcmp(optarg, "hms") == 0)
-        timestamp_set_seconds_type(TS_SECONDS_HOUR_MIN_SEC);
-      else {
-        cmdarg_err("Invalid seconds type \"%s\"; it must be one of:", optarg);
-        cmdarg_err_cont("\t\"s\"   for seconds\n"
-                        "\t\"hms\" for hours, minutes and seconds");
-        return 1;
-      }
-      break;
     case 'v':         /* Show version and exit */
-    {
+      comp_info_str = get_compiled_version_info(NULL, epan_get_compiled_version_info);
+      runtime_info_str = get_runtime_version_info(get_tfshark_runtime_version_info);
       show_version("TFShark (Wireshark)", comp_info_str, runtime_info_str);
       g_string_free(comp_info_str, TRUE);
       g_string_free(runtime_info_str, TRUE);
@@ -862,8 +806,10 @@ main(int argc, char *argv[])
        * $ ./tools/valgrind-wireshark -n
        * much more useful. */
       epan_cleanup();
+#ifdef HAVE_EXTCAP
+      extcap_cleanup();
+#endif
       return 0;
-    }
     case 'O':        /* Only output these protocols */
       /* already processed; just ignore it now */
       break;
@@ -896,6 +842,13 @@ main(int argc, char *argv[])
         return 1;
       }
       break;
+    case 'd':        /* Decode as rule */
+    case 'K':        /* Kerberos keytab file */
+    case 't':        /* Time stamp type */
+    case 'u':        /* Seconds type */
+      if (!dissect_opts_handle_opt(opt, optarg))
+          return 1;
+      break;
     default:
     case '?':        /* Bad flag - print usage message */
       print_usage(stderr);
@@ -990,6 +943,9 @@ main(int argc, char *argv[])
       cmdarg_err("%s", err_msg);
       g_free(err_msg);
       epan_cleanup();
+#ifdef HAVE_EXTCAP
+      extcap_cleanup();
+#endif
       return 2;
     }
   }
@@ -1000,6 +956,9 @@ main(int argc, char *argv[])
       cmdarg_err("%s", err_msg);
       g_free(err_msg);
       epan_cleanup();
+#ifdef HAVE_EXTCAP
+      extcap_cleanup();
+#endif
       return 2;
     }
   }
@@ -1045,6 +1004,9 @@ main(int argc, char *argv[])
        open_routine reader to use, then the following needs to change. */
     if (cf_open(&cfile, cf_name, WTAP_TYPE_AUTO, FALSE, &err) != CF_OK) {
       epan_cleanup();
+#ifdef HAVE_EXTCAP
+      extcap_cleanup();
+#endif
       return 2;
     }
 
@@ -1083,6 +1045,9 @@ main(int argc, char *argv[])
   funnel_dump_all_text_windows();
   epan_free(cfile.epan);
   epan_cleanup();
+#ifdef HAVE_EXTCAP
+  extcap_cleanup();
+#endif
 
   output_fields_free(output_fields);
   output_fields = NULL;
@@ -2074,7 +2039,7 @@ print_packet(capture_file *cf, epan_dissect_t *edt)
       break;
 
     case WRITE_XML:
-      write_pdml_proto_tree(edt, stdout);
+      write_pdml_proto_tree(NULL, NULL, edt, stdout);
       printf("\n");
       return !ferror(stdout);
     case WRITE_FIELDS: