Skip to content

workbench: Fix crash when a monitored entry is removed #1431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions workbench/src/wb_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ static void wb_monitor_entry_free (gpointer data)

/* Callback function for file monitoring. */
static void wb_monitor_file_changed_cb(G_GNUC_UNUSED GFileMonitor *monitor,
G_GNUC_UNUSED GFile *file,
G_GNUC_UNUSED GFile *other_file,
GFile *file,
GFile *other_file,
GFileMonitorEvent event,
WB_MONITOR_ENTRY *entry)
{
const gchar *event_string = NULL;
gchar *file_path, *other_file_path = NULL;
void (*handler) (WORKBENCH *, WB_PROJECT *, WB_PROJECT_DIR *, const gchar *) = NULL;

g_return_if_fail(entry != NULL);

Expand All @@ -111,14 +112,12 @@ static void wb_monitor_file_changed_cb(G_GNUC_UNUSED GFileMonitor *monitor,
{
case G_FILE_MONITOR_EVENT_CREATED:
event_string = "FILE_CREATED";
workbench_process_add_file_event (wb_globals.opened_wb,
entry->prj, entry->dir, file_path);
handler = workbench_process_add_file_event;
break;

case G_FILE_MONITOR_EVENT_DELETED:
event_string = "FILE_DELETED";
workbench_process_remove_file_event (wb_globals.opened_wb,
entry->prj, entry->dir, file_path);
handler = workbench_process_remove_file_event;
break;

default:
Expand All @@ -131,6 +130,13 @@ static void wb_monitor_file_changed_cb(G_GNUC_UNUSED GFileMonitor *monitor,
wb_project_dir_get_name(entry->dir), event_string, file_path);
}

if (handler != NULL)
{
/* The handler might destroy the entry, so we mustn't reference it any
* further after calling it */
handler (wb_globals.opened_wb, entry->prj, entry->dir, file_path);
}

g_free(file_path);
g_free(other_file_path);
}
Expand Down