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
Heap use after free in Squirrel delayed memory deallocation when AI deallocated #9267
Comments
At least it's since 47a99bb, though no clue yet what in that change causes this. Except that not running the garbage collection makes it work without problems. |
I fear the order of the objects in the |
seems to make the problem go away. |
Due to 47a99bb the order of elements in the garbage collection chain has changed causing the class to be finalised before the instances of that class. Since the instance's array of member values depends on the size of the values in the class, the class finalisation resetting that size to 0 causes not all finalisations to run, which subsequently causes a heap use after free. So, just set the SQObjectPtrs to 'null' during the finalisation of the SQClass so the SQInstance can release all instance variables during its finalisation.
Due to 47a99bb the order of elements in the garbage collection chain has changed causing the class to be finalised before the instances of that class. Since the instance's array of member values depends on the size of the values in the class, the class finalisation resetting that size to 0 causes not all finalisations to run, which subsequently causes a heap use after free. So, just set the SQObjectPtrs to 'null' during the finalisation of the SQClass so the SQInstance can release all instance variables during its finalisation.
Due to 47a99bb the order of elements in the garbage collection chain has changed causing the class to be finalised before the instances of that class. Since the instance's array of member values depends on the size of the values in the class, the class finalisation resetting that size to 0 causes not all finalisations to run, which subsequently causes a heap use after free. So, just set the SQObjectPtrs to 'null' during the finalisation of the SQClass so the SQInstance can release all instance variables during its finalisation.
Version of OpenTTD
1da0ba9, Linux, SDL2
Presumably since 47a99bb, 44d1b96
Expected result
No heap use after frees occur.
Actual result
Heap use after free (detected by AddressSanitizer) in Squirrel delayed memory deallocation when AI deallocated.
Details
Steps to reproduce
Start or load a game with an AI (my testing used NoCab).
Let the AI run for a few minutes so that it can allocate things.
Abandon or exit the game, such that the AI destructor is called.
See also
Original report: JGRennison/OpenTTD-patches#256
The text was updated successfully, but these errors were encountered: