Fix crash when reloading file more than once

markyd_app_open_file() invalidates the current path string, so calling
it with the pointer from markyd_app_get_current_path() works the first
time but causes a use-after-free on subsequent reloads. Copy the path
with g_strdup() before passing it to open_file, and free it afterwards.
This commit is contained in:
Aleksandar Colovic committed 2026-04-08 18:46:24 +02:00
1 parent 3d36df9847
commit a30ce043f4
1 file changed
+6 -3
+6 -3
View File
@@ -965,15 +965,17 @@ static void on_open_clicked(GtkButton *button, gpointer user_data) {
static void on_refresh_clicked(GtkButton *button, gpointer user_data) {
MarkydWindow *self = (MarkydWindow *)user_data;
const gchar *path;
const gchar *current;
gchar *path;
(void)button;
path = markyd_app_get_current_path(self->app);
if (!path || path[0] == '\0') {
current = markyd_app_get_current_path(self->app);
if (!current || current[0] == '\0') {
return;
}
path = g_strdup(current);
if (!markyd_app_open_file(self->app, path)) {
GtkWidget *error_dialog = gtk_message_dialog_new(
GTK_WINDOW(self->window),
@@ -984,6 +986,7 @@ static void on_refresh_clicked(GtkButton *button, gpointer user_data) {
gtk_dialog_run(GTK_DIALOG(error_dialog));
gtk_widget_destroy(error_dialog);
}
g_free(path);
}
static void on_settings_clicked(GtkButton *button, gpointer user_data) {