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

UPNP: Use local variable for UPNPUrls to stop memory leak. #89897

Merged
merged 1 commit into from
Apr 6, 2024

Conversation

alesliehughes
Copy link
Contributor

I've change the urls variable to be a local, instead of manually allocating it all the time. This is only used locally and was causing a memory leak because FreeUPNPUrls gave the impression it free it but didn't.

  1. FreeUPNPUrls doesn't free the pointer passed in, that's up to caller.
  2. The second if(!urls) produced dead code as we checked the pointer just after allocation.

@alesliehughes alesliehughes requested a review from a team as a code owner March 26, 2024 03:36
modules/upnp/upnp.cpp Outdated Show resolved Hide resolved
modules/upnp/upnp.cpp Outdated Show resolved Hide resolved
@Chaosus Chaosus added this to the 4.3 milestone Mar 26, 2024
@akien-mga akien-mga changed the title Use local variable to stop memory leak. UPNP: Use local variable to stop memory leak. Mar 26, 2024
@akien-mga akien-mga changed the title UPNP: Use local variable to stop memory leak. UPNP: Use local variable for UPNPUrls to stop memory leak. Mar 26, 2024
@mhilbrunner
Copy link
Member

because FreeUPNPUrls gave the impression it free it but didn't

Ouch, reading the upstream source, you are right. Seems whichever source I used as inspiration back when implementing this also got that part wrong.

I built this locally and found no issues during admittedly brief testing and the changes look good to me. I'm somewhat on the move this week but will try to do some more testing; in the mean time, this has my approval (with the above caveats).

Thanks for investigating and fixing issues you found :)

Comment on lines -141 to -144
if (!urls) {
dev->set_igd_status(UPNPDevice::IGD_STATUS_NO_URLS);
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

With the removal of this check, and of the previous one, IGD_STATUS_MALLOC_ERROR and IGD_STATUS_NO_URL are unused, and could be unexposed.

Unexposing them would break the API compatibility, but they can at least be flagged as deprecated and their documentation changed to clarify that they're never used.

I've change the urls variable to be a local, instead of manually allocating it all the time.
This is only used locally and was causing a memory leak because FreeUPNPUrls gave the impression it free it.

1. FreeUPNPUrls doesn't free the pointer passed in, that's up to caller.
2. The second if(!urls) produced dead code as we checked the pointer just after allocation.
@akien-mga akien-mga merged commit d619ffd into godotengine:master Apr 6, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants