Fix heap-after-free due to document rescan#4499
Conversation
|
Thanks. I will review later this week. |
|
looks like a |
|
Hi @sunderme. Often, when TexStudio is opened, and .tex files are rewritten or moved from VS Code (imagine I am using some agent). Or if I have some auto-generated .tex from a Python script, I run that script, regenerate .tex, and then TexStudio crashes. I am running the latest version on macOS 26.5.1. |
|
the file is open in txs while changed externally ? |
exactly. that is a much better description 🤔 |
|
Well, I don't get a crash, but let's see. |
|
I think, I would like to see a (simple) test case to recreate the issue. or you can check how it gets to "delete document" in your use case. |
|
Sure I will provide a simple test case by the end of the wee. Thanks! |
|
I still would like to see a real test case. |
|
can you check if txs still crashes on your end with latest changes ? |

Hi! First, thanks a lot for this fantastic project. I've been using it for several years.
I often struggle with crashes due to external updates to .tex files. While debugging, I got a use-after-free in LatexDocument::getListOfDocs(). Its result is cached in the project-shared lp->projectDocuments, but the cache was only invalidated in the two setMasterDocument paths. Every other mutation of the document set / master-child graph (deleteDocument, removeDocs, addDocument, addChild/removeChild) left stale.
So, for fixing it, I invalidated lp->projectDocuments on every graph mutation.
To confirm, added a unit test that confirms the exact crash pattern. Greetings!