Skip to content

Script afrer free access fix - #610

Open
MiranDMC wants to merge 2 commits into
masterfrom
Fix_deleted_script_access
Open

MiranDMC wants to merge 2 commits into
masterfrom
Fix_deleted_script_access

Conversation

@MiranDMC

@MiranDMC MiranDMC commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Fix allocated memory blocks summary accessing deleted scripts data during game session cleanup

Since now script structs are deleted right away, instead of waiting for game session to end it needs some consideration what else will start crashing now, including third party scripts and plugins.

@MiranDMC
MiranDMC requested a review from x87 October 3, 2026 17:03
Comment thread cleo_plugins/MemoryOperations/MemoryOperations.cpp Outdated
Comment thread cleo_plugins/MemoryOperations/MemoryOperations.cpp Outdated
Comment thread source/CCustomScript.cpp
Comment on lines +184 to +188
memset(this, 0, sizeof(CRunningScript)); // clear base script struct
strcpy_s(Name, "DELETED"); // upper case
m_ownedBuffer = nullptr;
m_parentScript = nullptr;
m_childScripts.clear();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zeroing this and setting Name in a destructor does not prevent use-after-free, as the memory block is reclaimed by the heap allocator immediately after the destructor returns (accessing it is still undefined behavior). Also, m_childScripts.clear() is redundant since std::list destructor runs automatically right after.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It prevents access to data I just nulled. Previously anybody who keep pointer to the just deleted script could use it without problems until that memory block was actually allocated and overwritten by something else.
I would not trust m_childScripts destructor to clear fields internal fields like count in the object that is about to be deleted anyway.

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