Skip to content

Fix error when reloading file more than once#1

Merged
rabfulton merged 1 commit intorabfulton:masterfrom
FenrirTheGray:fix/reload-file-crash
Apr 10, 2026
Merged

Fix error when reloading file more than once#1
rabfulton merged 1 commit intorabfulton:masterfrom
FenrirTheGray:fix/reload-file-crash

Conversation

@FenrirTheGray
Copy link
Copy Markdown
Contributor

Repro Steps:

  1. Open a markdown file
  2. Press the "Reload Current Document" button multiple times

Expected Results:

  • Document is successfully reloaded

Actual Results:

  • An error stating "Failed to reload document" pops up

Issue Summary

on_refresh_clicked() passes the pointer from markyd_app_get_current_path() directly to markyd_app_open_file(), which invalidates that pointer internally. The first reload works, but subsequent reloads cause a use-after-free, which leads to the aforementioned error.

This fix copies the path with g_strdup() before passing it to open_file, and frees it afterwards.

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.
@FenrirTheGray
Copy link
Copy Markdown
Contributor Author

Hey @rabfulton !

Can you please review this PR?

@rabfulton
Copy link
Copy Markdown
Owner

Thank you for spotting and fixing this, was out of town for a few days and have only just got a chance to take a look.

@rabfulton rabfulton merged commit effa685 into rabfulton:master Apr 10, 2026
@FenrirTheGray
Copy link
Copy Markdown
Contributor Author

No problem!
Glad I was able to contribute.

Love the app!
Thanks for making it! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants