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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/SunMoonCalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ SunMoonCalc::Result SunMoonCalc::calculateSunAndMoonData(){
} else {
// Update Sun's maximum elevation
setUTDate(sun.transitJd);
delete[] out;
out = doCalc(getSunPosition());
sun.transitElevation = out[5];
}
Expand All @@ -191,6 +192,7 @@ SunMoonCalc::Result SunMoonCalc::calculateSunAndMoonData(){

const PositionalData moonPosition = getMoonPosition();
double moonLat = moonPosition.latitude, moonLon = moonPosition.longitude;
delete[] out;
out = doCalc(moonPosition);

moon.azimuth = out[0];
Expand All @@ -216,18 +218,21 @@ SunMoonCalc::Result SunMoonCalc::calculateSunAndMoonData(){
// Update Moon's maximum elevation
setUTDate(moon.transitJd);
getSunPosition();
delete[] out;
out = doCalc(getMoonPosition());
moon.transitElevation = out[5];
}
setUTDate(jd);
this->sanomaly = sa;
this->slongitude = sl;
this->moonAge = ma;


delete[] out;
out = getMoonDiskOrientationAngles(lst, sunRA, sunDec, radians(moonLon),radians(moonLat), moonRA, moonDec);
moon.axisPositionAngle = out[2];
moon.brightLimbAngle = out[3];
moon.paralacticAngle = out[4];
delete[] out;
moon.age = ma;
moon.phase = calculateMoonPhase(moon.age);

Expand Down Expand Up @@ -372,7 +377,7 @@ SunMoonCalc::PositionalData SunMoonCalc::getMoonPosition() {
* - lst
*/
double *SunMoonCalc::doCalc(PositionalData position) {
auto arr = new double[10];
double* arr = new double[10];

// Ecliptic to equatorial coordinates
double t2 = this->t / 100.0;
Expand Down Expand Up @@ -584,6 +589,7 @@ double SunMoonCalc::obtainAccurateRiseSetTransit(double riseSetJd, const int ind
}
step = fabs(riseSetJd - out[index]);
riseSetJd = out[index];
delete[] out;
}
if (step > 1.0 / SECONDS_PER_DAY) return -1; // did not converge => without rise/set/transit in this date
return riseSetJd;
Expand All @@ -600,8 +606,8 @@ double SunMoonCalc::obtainAccurateRiseSetTransit(double riseSetJd, const int ind
double *SunMoonCalc::getMoonDiskOrientationAngles(double lst, double sunRA, double sunDec, double moonLon,
double moonLat, double moonRA, double moonDec) {

auto arr = new double[5];

double* arr = new double[5];
// Moon's argument of latitude
double F = radians(93.2720993 + 483202.0175273 * this->t - 0.0034029 * this->t * this->t -
this->t * this->t * this->t / 3526000.0 + this->t * this->t * this->t * this->t / 863310000.0);
Expand Down