Commit 2fd9c50b14ced59e40e10138ebd65a1921768f9a
1 parent
3ff175f6
Prevent memory leak in restoration of curvature matrix
Showing
1 changed file
with
4 additions
and
6 deletions
src/ctlike/ctlike.cpp
| @@ -228,12 +228,9 @@ void ctlike::run(void) | @@ -228,12 +228,9 @@ void ctlike::run(void) | ||
| 228 | // Optimize model parameters using LM optimizer | 228 | // Optimize model parameters using LM optimizer |
| 229 | optimize_lm(); | 229 | optimize_lm(); |
| 230 | 230 | ||
| 231 | - // Get pointer to curvature matrix | ||
| 232 | - GMatrixSparse* curvature_ptr = | ||
| 233 | - const_cast<GObservations::likelihood&>(m_obs.function()).curvature(); | ||
| 234 | - | ||
| 235 | // Store copy of curvature matrix | 231 | // Store copy of curvature matrix |
| 236 | - GMatrixSparse curvature = *curvature_ptr; | 232 | + GMatrixSparse curvature = |
| 233 | + *(const_cast<GObservations::likelihood&>(m_obs.function()).curvature()); | ||
| 237 | 234 | ||
| 238 | // Store Npred | 235 | // Store Npred |
| 239 | double npred = m_obs.npred(); | 236 | double npred = m_obs.npred(); |
| @@ -313,7 +310,8 @@ void ctlike::run(void) | @@ -313,7 +310,8 @@ void ctlike::run(void) | ||
| 313 | restore_edisp(m_obs, save_edisp); | 310 | restore_edisp(m_obs, save_edisp); |
| 314 | 311 | ||
| 315 | // Restore curvature matrix | 312 | // Restore curvature matrix |
| 316 | - *curvature_ptr = curvature; | 313 | + *(const_cast<GObservations::likelihood&>(m_obs.function()).curvature()) = |
| 314 | + curvature; | ||
| 317 | 315 | ||
| 318 | // Return | 316 | // Return |
| 319 | return; | 317 | return; |