aboutsummaryrefslogtreecommitdiffstats
path: root/tshark.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2020-03-25 13:38:11 -0700
committerGuy Harris <gharris@sonic.net>2020-03-25 20:59:37 +0000
commit3662a69036f33a169301cfc76bd3a3c09023a68d (patch)
tree354eee63060eb764ed162b394b7e8ce327166ad8 /tshark.c
parent439005cc2c78258d47a85e4b161df9c37041e60a (diff)
Maintain cf->state, because file cleanup depends on it.
If we're capturing to multiple files, whenever we are told about a new file, we must close the old file, so we don't leak file descriptors and wtap structures. Have cf_close() handle the work of closing, the way it does in file.c, and, when we *open* a file, set the state in capture_file to FILE_READ_IN_PROGRESS. Bug: 16457 Change-Id: I04a01c30571b7e3575dee5e7252a59bb1ee8abbc Reviewed-on: https://code.wireshark.org/review/36580 Petri-Dish: Guy Harris <gharris@sonic.net> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <gharris@sonic.net>
Diffstat (limited to 'tshark.c')
-rw-r--r--tshark.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/tshark.c b/tshark.c
index c4911c6b22..6edba77dd5 100644
--- a/tshark.c
+++ b/tshark.c
@@ -2635,11 +2635,7 @@ capture_input_new_file(capture_session *cap_session, gchar *new_file)
/* we start a new capture file, close the old one (if we had one before) */
if (cf->state != FILE_CLOSED) {
- if (cf->provider.wth != NULL) {
- wtap_close(cf->provider.wth);
- cf->provider.wth = NULL;
- }
- cf->state = FILE_CLOSED;
+ cf_close(cf);
}
g_free(capture_opts->save_file);
@@ -2858,21 +2854,13 @@ capture_input_drops(capture_session *cap_session _U_, guint32 dropped, const cha
* do the required cleanup.
*/
void
-capture_input_closed(capture_session *cap_session, gchar *msg)
+capture_input_closed(capture_session *cap_session _U_, gchar *msg)
{
- capture_file *cf = cap_session->cf;
-
if (msg != NULL)
fprintf(stderr, "tshark: %s\n", msg);
report_counts();
- if (cf != NULL && cf->provider.wth != NULL) {
- wtap_close(cf->provider.wth);
- if (cf->is_tempfile) {
- ws_unlink(cf->filename);
- }
- }
#ifdef USE_BROKEN_G_MAIN_LOOP
/*g_main_loop_quit(loop);*/
g_main_loop_quit(loop);
@@ -4250,7 +4238,24 @@ write_finale(void)
void
cf_close(capture_file *cf)
{
- g_free(cf->filename);
+ if (cf->state == FILE_CLOSED)
+ return; /* Nothing to do */
+
+ if (cf->provider.wth != NULL) {
+ wtap_close(cf->provider.wth);
+ cf->provider.wth = NULL;
+ }
+ /* We have no file open... */
+ if (cf->filename != NULL) {
+ /* If it's a temporary file, remove it. */
+ if (cf->is_tempfile)
+ ws_unlink(cf->filename);
+ g_free(cf->filename);
+ cf->filename = NULL;
+ }
+
+ /* We have no file open. */
+ cf->state = FILE_CLOSED;
}
cf_status_t
@@ -4290,6 +4295,8 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
cf->provider.prev_dis = NULL;
cf->provider.prev_cap = NULL;
+ cf->state = FILE_READ_IN_PROGRESS;
+
/* Create new epan session for dissection. */
epan_free(cf->epan);
cf->epan = tshark_epan_new(cf);