Fix a few minor memory leaks...
[obnox/wireshark/wip.git] / file.c
diff --git a/file.c b/file.c
index 071d2b571877b7890a3750673001a855d2645965..799130b6153cf6e918b8d746f2faa6de839a5aae 100644 (file)
--- a/file.c
+++ b/file.c
@@ -77,7 +77,6 @@
 #include <wsutil/file_util.h>
 #include <epan/column-utils.h>
 #include <epan/strutil.h>
-#include <epan/emem.h>
 
 #ifdef HAVE_LIBPCAP
 gboolean auto_scroll_live;
@@ -350,6 +349,7 @@ cf_reset_state(capture_file *cf)
 
   /* No frame selected, no field in that frame selected. */
   cf->current_frame = NULL;
+  cf->current_row = 0;
   cf->finfo_selected = NULL;
 
   /* Clear the packet list. */
@@ -404,7 +404,6 @@ cf_read(capture_file *cf)
   const gchar *name_ptr;
   const char  *errmsg;
   char         errmsg_errno[1024+1];
-  gchar        err_str[2048+1];
   gint64       data_offset;
   progdlg_t *volatile progbar = NULL;
   gboolean     stop_flag;
@@ -568,6 +567,8 @@ cf_read(capture_file *cf)
   cf->lnk_t = wtap_file_encap(cf->wth);
 
   cf->current_frame = cf->first_displayed;
+  cf->current_row = 0;
+
   packet_list_thaw();
 
   cf_callback_invoke(cf_cb_file_read_finished, cf);
@@ -628,8 +629,7 @@ cf_read(capture_file *cf)
       errmsg = errmsg_errno;
       break;
     }
-    g_snprintf(err_str, sizeof err_str, errmsg);
-    simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, err_str);
+    simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", errmsg);
     return CF_READ_ERROR;
   } else
     return CF_READ_OK;
@@ -1123,7 +1123,9 @@ read_packet(capture_file *cf, dfilter_t *dfcode, gint64 offset)
     cf->count++;
     cf->f_datalen = offset + phdr->caplen;
     fdata->num = cf->count;
-    row = add_packet_to_packet_list(fdata, cf, dfcode, pseudo_header, buf, TRUE);
+    if (!cf->redissecting) {
+      row = add_packet_to_packet_list(fdata, cf, dfcode, pseudo_header, buf, TRUE);
+    }
   } else {
     /* XXX - if we didn't have read filters, or if we could avoid
        allocating the "frame_data" structure until we knew whether
@@ -1154,7 +1156,6 @@ cf_merge_files(char **out_filenamep, int in_file_count,
   int               err_fileno;
   int               i;
   char              errmsg_errno[1024+1];
-  gchar             err_str[2048+1];
   const char       *errmsg;
   gboolean          got_read_error = FALSE, got_write_error = FALSE;
   gint64            data_offset;
@@ -1346,8 +1347,7 @@ cf_merge_files(char **out_filenamep, int in_file_count,
          errmsg = errmsg_errno;
          break;
        }
-       g_snprintf(err_str, sizeof err_str, errmsg, in_files[i].filename);
-        simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, err_str);
+        simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, errmsg, in_files[i].filename);
       }
     }
   }
@@ -1516,6 +1516,10 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
        which might cause the state information to be constructed differently
        by that dissector. */
 
+    /* We might receive new packets while redissecting, and we don't
+       want to dissect those before their time. */
+    cf->redissecting = TRUE;
+
     /* Initialize all data structures used for dissection. */
     init_dissection();
   }
@@ -1662,6 +1666,9 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
     prev_frame = fdata;
   }
 
+  /* We are done redissecting the packet list. */
+  cf->redissecting = FALSE;
+
   /* Re-sort the list using the previously selected order */
   packet_list_set_sort_column();
 
@@ -1732,6 +1739,10 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
     /* Either the frame that was selected passed the filter, or we've
        found the nearest displayed frame to that frame.  Select it, make
        it the focus row, and make it visible. */
+    if (selected_row == 0) {
+      /* Set to invalid to force update of packet list and packet details */
+      cf->current_row = -1;
+    }
     packet_list_set_selected_row(selected_row);
   }
 
@@ -3338,6 +3349,7 @@ cf_select_packet(capture_file *cf, int row)
 
   /* Record that this frame is the current frame. */
   cf->current_frame = fdata;
+  cf->current_row = row;
 
   /* Create the logical protocol tree. */
   if (cf->edt != NULL) {
@@ -3367,6 +3379,7 @@ cf_unselect_packet(capture_file *cf)
 
   /* No packet is selected. */
   cf->current_frame = NULL;
+  cf->current_row = 0;
 
   cf_callback_invoke(cf_cb_packet_unselected, cf);