Fix use after free with script timing in LuaMan.cpp #220
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In
RunScriptFunctionObject
, script timing is calculated before/after running the script, then written intoPerformanceMan::m_ScriptTimings
table based on the path to the script. This introduces a use-after-free error and likely crashing if the script in question deallocates the function object, like Combat Shield's "Detach" pie menu option deleting itself: #219My fix here is to get the table entry before running the script, store a pointer to it in a variable, and then access it directly after running the script. This also removes the double lookup into the unordered_map.
In my testing, this fixes the issue entirely. I'm not knowledgeable on this codebase or on C++isms, I don't know what's the policy of the project on raw pointers, so if this doesn't fit, please feel free to disregard this and implement an equivalent kind of a solution in proper language etiquette instead lol
Fixes #219