Qt: Handle errors when reloading Lua FileHandler

Reloading the capture file after reloading a Lua FileHandler
may fail because of Lua errors. Handle this by closing the file.

Related to #17615
This commit is contained in:
Stig Bjørlykke 2021-10-03 21:16:16 +02:00 committed by Wireshark GitLab Utility
parent 5c185238a4
commit e866034c55
3 changed files with 12 additions and 9 deletions

14
file.c
View File

@ -4962,15 +4962,16 @@ cf_rename_failure_alert_box(const char *filename, int err)
} }
/* Reload the current capture file. */ /* Reload the current capture file. */
void cf_status_t
cf_reload(capture_file *cf) { cf_reload(capture_file *cf) {
gchar *filename; gchar *filename;
gboolean is_tempfile; gboolean is_tempfile;
cf_status_t cf_status = CF_OK;
int err; int err;
if (cf->read_lock) { if (cf->read_lock) {
ws_warning("Failing cf_reload(\"%s\") since a read is in progress", cf->filename); ws_warning("Failing cf_reload(\"%s\") since a read is in progress", cf->filename);
return; return CF_ERROR;
} }
/* If the file could be opened, "cf_open()" calls "cf_close()" /* If the file could be opened, "cf_open()" calls "cf_close()"
@ -4998,11 +4999,8 @@ cf_reload(capture_file *cf) {
case CF_READ_ABORTED: case CF_READ_ABORTED:
/* The user bailed out of re-reading the capture file; the /* The user bailed out of re-reading the capture file; the
capture file has been closed - just free the capture file name capture file has been closed. */
string and return (without changing the last containing break;
directory). */
g_free(filename);
return;
} }
} else { } else {
/* The open failed, so "cf->is_tempfile" wasn't set to "is_tempfile". /* The open failed, so "cf->is_tempfile" wasn't set to "is_tempfile".
@ -5012,10 +5010,12 @@ cf_reload(capture_file *cf) {
XXX - change the menu? Presumably "cf_open()" will do that; XXX - change the menu? Presumably "cf_open()" will do that;
make sure it does! */ make sure it does! */
cf->is_tempfile = is_tempfile; cf->is_tempfile = is_tempfile;
cf_status = CF_ERROR;
} }
/* "cf_open()" made a copy of the file name we handed it, so /* "cf_open()" made a copy of the file name we handed it, so
we should free up our copy. */ we should free up our copy. */
g_free(filename); g_free(filename);
return cf_status;
} }
/* /*

3
file.h
View File

@ -135,8 +135,9 @@ void cf_close(capture_file *cf);
* Reload a capture file. * Reload a capture file.
* *
* @param cf the capture file to be reloaded * @param cf the capture file to be reloaded
* @return one of cf_status_t
*/ */
void cf_reload(capture_file *cf); cf_status_t cf_reload(capture_file *cf);
/** /**
* Read all packets of a capture file into the internal structures. * Read all packets of a capture file into the internal structures.

View File

@ -1563,7 +1563,9 @@ void MainWindow::reloadLuaPlugins()
if (uses_lua_filehandler) { if (uses_lua_filehandler) {
// Reload the file in case the FileHandler has changed // Reload the file in case the FileHandler has changed
cf_reload(capture_file_.capFile()); if (cf_reload(capture_file_.capFile()) != CF_OK) {
cf_close(capture_file_.capFile());
}
proto_free_deregistered_fields(); proto_free_deregistered_fields();
} else { } else {
redissectPackets(); redissectPackets();