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

Fixed memory leak (#144) #155

Merged
merged 1 commit into from
Mar 21, 2019
Merged

Fixed memory leak (#144) #155

merged 1 commit into from
Mar 21, 2019

Conversation

jgromes
Copy link
Contributor

@jgromes jgromes commented Mar 21, 2019

Fixes #144.

Methods SunMoonCalc::doCalc() and SunMoonCalc::getMoonDiskOrientationAngles() return pointers to dynamically allocated pointers, which the callers then never deleted, hence the memory leak. Everything is now deleted before reallocating/caller exiting.

@marcelstoer marcelstoer merged commit 53d3aea into ThingPulse:master Mar 21, 2019
@marcelstoer
Copy link
Member

Thanks for the fix. Great job.

Is there a convention or common practice where (in the code) to place delete[] or delete? For example here

https://github.com/ThingPulse/esp8266-weather-station/blob/master/src/SunMoonCalc.cpp#L183

you're clearing the allocated memory right before out is reassigned. One could also do that a few lines above after the values from out are last used i.e.

https://github.com/ThingPulse/esp8266-weather-station/blob/master/src/SunMoonCalc.cpp#L173.

@jgromes
Copy link
Contributor Author

jgromes commented Mar 22, 2019

I don't think there's a convention, the memory just has to dealloacted before the function returns or before the memory gets reallocated.

@marcelstoer
Copy link
Member

Yep, and one could probably argue that the code is a tad more legible of it's done right before reallocation.

@Leonos
Copy link

Leonos commented Apr 9, 2019

Wow, I almost missed this. This is great, thank you @marcelstoer and especially @jgromes!!

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.

3 participants