Skip to content

[VSCRIPT] Memory leak on instances returned from C++ #104

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

Closed
samisalreadytaken opened this issue Mar 7, 2021 · 2 comments
Closed

[VSCRIPT] Memory leak on instances returned from C++ #104

samisalreadytaken opened this issue Mar 7, 2021 · 2 comments
Labels
Bug Something isn't working VScript Mapbase - Involves VScript

Comments

@samisalreadytaken
Copy link

samisalreadytaken commented Mar 7, 2021

Describe the bug

Instances returned from native functions are not released.

Steps to reproduce

Call any native function that returns an instance, watch the memory usage.

for ( local i = 1000000; i--; )
	player.GetOrigin()
@samisalreadytaken samisalreadytaken added Bug Something isn't working VScript Mapbase - Involves VScript labels Mar 7, 2021
@Blixibon Blixibon pinned this issue Apr 19, 2021
@samisalreadytaken
Copy link
Author

Fix for Vectors by manually freeing the return value. This does not fix for hscript. Strings are not leaked, doing this for them crashes, so the current non-functional retval.Free() is actually dangerous here.

@@ -1404,7 +1404,8 @@ SQInteger function_stub(HSQUIRRELVM vm)

        PushVariant(vm, retval);

-       retval.Free();
+       if ( retval.m_type == FIELD_VECTOR )
+               delete retval.m_pVector;

        return pFunc->m_desc.m_ReturnType != FIELD_VOID;
 }

function_stub may need a refactor because of all these leaks.

@samisalreadytaken
Copy link
Author

This was fixed years ago.

@Blixibon Blixibon unpinned this issue Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working VScript Mapbase - Involves VScript
Projects
None yet
Development

No branches or pull requests

1 participant