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

how do i override a pointer to avoid memory leak #25

Open
olwethumlimi opened this issue Feb 12, 2023 · 1 comment
Open

how do i override a pointer to avoid memory leak #25

olwethumlimi opened this issue Feb 12, 2023 · 1 comment

Comments

@olwethumlimi
Copy link

e.g

char *  message;
 message = tgc_alloc(&gc, 10); // it allocate
 strcpy(message, "test"); 
 message ="update" // override the value, 
@olwethumlimi olwethumlimi changed the title how to i override a pointer to avoid memory leak how do i override a pointer to avoid memory leak Feb 12, 2023
@RolandMarchand
Copy link

In your example at line 4, the pointer from line 2 became unreachable., since message is now pointing at the string literal "update". The memory allocated at line 2 will be freed automatically.

If you're really concerned about memory leaks, you can run tgc_free() on the original pointer.

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

2 participants