Skip to content
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

[bug?] a memory leak? #155

Open
DanielMazurkiewicz opened this issue Jun 2, 2022 · 4 comments
Open

[bug?] a memory leak? #155

DanielMazurkiewicz opened this issue Jun 2, 2022 · 4 comments

Comments

@DanielMazurkiewicz
Copy link

char *buffer = new char[size + 1]; //we need extra char for NUL

I might be missing something, but I didn't see any place that does free it, is not that a memory leak?

@RobLoach
Copy link
Owner

RobLoach commented Jun 2, 2022

Good question... There was a CleanUp process in the old bindings. Perhaps the new ones are missing that clean step.

@konsumer
Copy link
Collaborator

konsumer commented Jun 2, 2022

I could be wrong, but it's my understanding that NAPI manages all the FromValue/ToValue stuff. I was worried about memory-leaks at first, but it seems like it calls & frees them in the normal js GC lifecycle. It might be a good idea to try to auto-detect leaks just in case, but outside of these To/From calls nothing should be allocated, so I think we are mostly safe.

Are strings causing an actual problem?

@twuky
Copy link
Collaborator

twuky commented Jun 10, 2022

I'm also really not an expert when it comes to working with memory in C but looking at it now, this probably does leak? The way the bindings are supposed to look, the string itself should be okay to discard once the function its used for is done (and it wouldnt affect anything the user has saved in JS, its just a copy). So we probably need to add another condition to the code generator for functions with string arguments:

  • first, get all strings from arguments using stringFromValue() and save to individual variables
  • call the raylib function with the strings
  • then free before returning

I'm just not sure personally what it looks like to free that memory, i basically only know enough about C to have gotten the bindings to compile...

@konsumer
Copy link
Collaborator

konsumer commented Jun 10, 2022

Maybe a first step is to verify our idea of this (as we disagree on if it's a leak or not.) How do we determine it is? This seems like it might help detect them. So, what is the test for it? Do we run a bunch of node-raylib functions that pass strings, and see if we hit a leak?

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

No branches or pull requests

4 participants