From 8aa3da53d9ae061f08070c142f3ed45abf63e2aa Mon Sep 17 00:00:00 2001
From: John Thacker <johnthacker@gmail.com>
Date: Sun, 19 Apr 2026 11:45:40 -0400
Subject: [PATCH] sharkd: Empty the filter table when loading a new file

The cached filter results need to be emptied when a new file is loaded,
since they are likely not accurate for the new file.

FIx #21207

AI-Assisted: no


(cherry picked from commit a8f60a2a35623166212100ecbd5d63bcfa36c63a)

Co-authored-by: John Thacker <johnthacker@gmail.com>
---
 sharkd_session.c | 5 +++++
 1 file changed, 5 insertions(+)

Index: wireshark-3.6.24/sharkd_session.c
===================================================================
--- wireshark-3.6.24.orig/sharkd_session.c
+++ wireshark-3.6.24/sharkd_session.c
@@ -1074,6 +1074,10 @@ sharkd_session_process_load(const char *
 		return;
 	}
 
+    /* The open succeded, and any previous file was closed. Remove any filter
+     * results that refer to the previous file. */
+    g_hash_table_remove_all(filter_table);
+
 	TRY
 	{
 		err = sharkd_load_cap_file();
@@ -5045,6 +5049,7 @@ sharkd_session_main(int mode_setting)
 
 	dumper.output_file = stdout;
 
+	/* XXX - This could be a wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(),...) */
 	filter_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, sharkd_session_filter_free);
 
 #ifdef HAVE_MAXMINDDB
