Commit 2fd9c50b14ced59e40e10138ebd65a1921768f9a

Authored by Jürgen Knödlseder
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 228 // Optimize model parameters using LM optimizer
229 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 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 235 // Store Npred
239 236 double npred = m_obs.npred();
... ... @@ -313,7 +310,8 @@ void ctlike::run(void)
313 310 restore_edisp(m_obs, save_edisp);
314 311  
315 312 // Restore curvature matrix
316   - *curvature_ptr = curvature;
  313 + *(const_cast<GObservations::likelihood&>(m_obs.function()).curvature()) =
  314 + curvature;
317 315  
318 316 // Return
319 317 return;
... ...