Revert "Use g_ alloced memory (instead of emem) when printing fields. emem shouldn...
authorEvan Huus <eapache@gmail.com>
Fri, 9 May 2014 15:16:14 +0000 (15:16 +0000)
committerEvan Huus <eapache@gmail.com>
Fri, 9 May 2014 15:19:59 +0000 (15:19 +0000)
It's causing a few different test failures - I've tracked down at least one of them, but the others are weirder and will require more digging.

This reverts commit 9edba650d11776fa1d5aefe4820890898380c1c2.

Change-Id: I897f8cf1cfbb2a189b2054e5002f59757befa47f
Reviewed-on: https://code.wireshark.org/review/1575
Reviewed-by: Evan Huus <eapache@gmail.com>
epan/print.c
epan/print.h
ui/gtk/main.c
ui/qt/main_window_slots.cpp

index 36a8bc7d25a018f83c3f1b2b8411f4b2c3be95e3..8a4ffa8e6394cd18e4f5988a4c38d12930748001 100644 (file)
@@ -91,7 +91,7 @@ GHashTable *output_only_tables = NULL;
 
 static gboolean write_headers = FALSE;
 
-static gchar *get_field_hex_value(GSList *src_list, field_info *fi);
+static const gchar *get_field_hex_value(GSList *src_list, field_info *fi);
 static void proto_tree_print_node(proto_node *node, gpointer data);
 static void proto_tree_write_node_pdml(proto_node *node, gpointer data);
 static const guint8 *get_field_data(GSList *src_list, field_info *fi);
@@ -425,7 +425,10 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
             fputs("\" show=\"\" value=\"",  pdata->fh);
             break;
         default:
-            dfilter_string = fvalue_to_string_repr(&fi->value, FTREPR_DISPLAY, NULL);
+            /* XXX - this is a hack until we can just call
+             * fvalue_to_string_repr() for *all* FT_* types. */
+            dfilter_string = proto_construct_match_selected_string(fi,
+                                                                   pdata->edt);
             if (dfilter_string != NULL) {
                 chop_len = strlen(fi->hfinfo->abbrev) + 4; /* for " == " */
 
@@ -442,7 +445,6 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
                 fputs("\" show=\"", pdata->fh);
                 print_escaped_xml(pdata->fh, &dfilter_string[chop_len]);
             }
-            g_free(dfilter_string);
 
             /*
              * XXX - should we omit "value" for any fields?
@@ -471,7 +473,7 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
                             break;
                         case FT_INT64:
                         case FT_UINT64:
-                            fprintf(pdata->fh, "%" G_GINT64_MODIFIER "X",
+                            g_fprintf(pdata->fh, "%" G_GINT64_MODIFIER "X",
                                     fvalue_get_integer64(&fi->value));
                             break;
                         default:
@@ -1632,7 +1634,6 @@ static void proto_tree_get_node_field_values(proto_node *node, gpointer data)
     write_field_data_t *call_data;
     field_info *fi;
     gpointer    field_index;
-    gchar      *field_str;
 
     call_data = (write_field_data_t *)data;
     fi = PNODE_FINFO(node);
@@ -1642,9 +1643,9 @@ static void proto_tree_get_node_field_values(proto_node *node, gpointer data)
 
     field_index = g_hash_table_lookup(call_data->fields->field_indicies, fi->hfinfo->abbrev);
     if (NULL != field_index) {
-        field_str = get_node_field_value(fi, call_data->edt); /* g_ alloced string */
-        format_field_values(call_data->fields, field_index, field_str);
-        g_free(field_str);
+        format_field_values(call_data->fields, field_index,
+                            get_node_field_value(fi, call_data->edt) /* static or ep_alloc'd string */
+            );
     }
 
     /* Recurse here. */
@@ -1740,14 +1741,14 @@ void write_fields_finale(output_fields_t* fields _U_ , FILE *fh _U_)
     /* Nothing to do */
 }
 
-/* Returns an g_malloced string */
-gchar* get_node_field_value(field_info* fi, epan_dissect_t* edt)
+/* Returns an ep_alloced string or a static constant*/
+const gchar* get_node_field_value(field_info* fi, epan_dissect_t* edt)
 {
     if (fi->hfinfo->id == hf_text_only) {
         /* Text label.
          * Get the text */
         if (fi->rep) {
-            return g_strdup(fi->rep->representation);
+            return fi->rep->representation;
         }
         else {
             return get_field_hex_value(edt->pi.data_src, fi);
@@ -1768,17 +1769,20 @@ gchar* get_node_field_value(field_info* fi, epan_dissect_t* edt)
         case FT_PROTOCOL:
             /* Print out the full details for the protocol. */
             if (fi->rep) {
-                return g_strdup(fi->rep->representation);
+                return fi->rep->representation;
             } else {
                 /* Just print out the protocol abbreviation */
-                return g_strdup(fi->hfinfo->abbrev);
+                return fi->hfinfo->abbrev;
             }
         case FT_NONE:
             /* Return "1" so that the presence of a field of type
              * FT_NONE can be checked when using -T fields */
             return g_strdup("1");
         default:
-            dfilter_string = fvalue_to_string_repr(&fi->value, FTREPR_DISPLAY, NULL);
+            /* XXX - this is a hack until we can just call
+             * fvalue_to_string_repr() for *all* FT_* types. */
+            dfilter_string = proto_construct_match_selected_string(fi,
+                                                                   edt);
             if (dfilter_string != NULL) {
                 chop_len = strlen(fi->hfinfo->abbrev) + 4; /* for " == " */
 
@@ -1800,7 +1804,7 @@ gchar* get_node_field_value(field_info* fi, epan_dissect_t* edt)
     }
 }
 
-static gchar*
+static const gchar*
 get_field_hex_value(GSList *src_list, field_info *fi)
 {
     const guint8 *pd;
@@ -1823,7 +1827,7 @@ get_field_hex_value(GSList *src_list, field_info *fi)
         const int  chars_per_byte = 2;
 
         len    = chars_per_byte * fi->length;
-        buffer = (gchar *)g_malloc(sizeof(gchar)*(len + 1));
+        buffer = ep_alloc_array(gchar, len + 1);
         buffer[len] = '\0'; /* Ensure NULL termination in bad cases */
         p = buffer;
         /* Print a simple hex dump */
index be739f248baaf0d1fa701ce9bbbedcad3cdd1333..76fe08f56fd582dc9d06a8ed762f2e66f0a19cb5 100644 (file)
@@ -157,7 +157,7 @@ WS_DLL_PUBLIC void write_fields_preamble(output_fields_t* fields, FILE *fh);
 WS_DLL_PUBLIC void proto_tree_write_fields(output_fields_t* fields, epan_dissect_t *edt, column_info *cinfo, FILE *fh);
 WS_DLL_PUBLIC void write_fields_finale(output_fields_t* fields, FILE *fh);
 
-WS_DLL_PUBLIC gchar* get_node_field_value(field_info* fi, epan_dissect_t* edt);
+WS_DLL_PUBLIC const gchar* get_node_field_value(field_info* fi, epan_dissect_t* edt);
 
 #ifdef __cplusplus
 }
index e49e0531a0131263a19f134588b49127a9230958..56264fb305a55de2f8bece724e96448bda02debd 100644 (file)
@@ -668,9 +668,8 @@ copy_selected_plist_cb(GtkWidget *w _U_, gpointer data _U_, COPY_SELECTED_E acti
         break;
     case COPY_SELECTED_VALUE:
         if (cfile.edt !=0 ) {
-            gchar* field_str = get_node_field_value(cfile.finfo_selected, cfile.edt);
-            g_string_append(gtk_text_str, field_str);
-            g_free(field_str);
+            g_string_append(gtk_text_str,
+                    get_node_field_value(cfile.finfo_selected, cfile.edt));
         }
         break;
     default:
index be4a5ad8a0c470d614b94b4c858ab686e3fa7ba4..7bbb4486d9e5625c1300e17c6425949fef8c3215 100644 (file)
@@ -1424,9 +1424,7 @@ void MainWindow::actionEditCopyTriggered(MainWindow::CopySelected selection_type
         break;
     case CopySelectedValue:
         if (cap_file_->edt != 0) {
-            gchar* field_str = get_node_field_value(cap_file_->finfo_selected, cap_file_->edt);
-            clip.append(field_str);
-            g_free(field_str);
+            clip.append(get_node_field_value(cap_file_->finfo_selected, cap_file_->edt));
         }
         break;
     }