]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix memory leak in KINSOL wrapper 6389/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 29 Apr 2018 21:04:42 +0000 (23:04 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 29 Apr 2018 21:05:13 +0000 (23:05 +0200)
source/sundials/kinsol.cc

index 4390ec1a266fcb3c0dba9cefe7a5675caee8f1c7..e1817e7f3369422ffbfe9aba6fd1ec03943cdc51 100644 (file)
@@ -264,6 +264,11 @@ namespace SUNDIALS
     status = KINSetRelErrFunc(kinsol_mem, data.dq_relative_error);
     AssertKINSOL(status);
 
+#if DEAL_II_SUNDIALS_VERSION_GTE(3,0,0)
+    SUNMatrix J;
+    SUNLinearSolver LS;
+#endif
+
     if (solve_jacobian_system)
       {
         KINMem KIN_mem = (KINMem) kinsol_mem;
@@ -279,8 +284,8 @@ namespace SUNDIALS
     else
       {
 #if DEAL_II_SUNDIALS_VERSION_GTE(3,0,0)
-        const auto J = SUNDenseMatrix(system_size, system_size);
-        const auto LS = SUNDenseLinearSolver(u_scale, J);
+        J = SUNDenseMatrix(system_size, system_size);
+        LS = SUNDenseLinearSolver(u_scale, J);
         status = KINDlsSetLinearSolver(kinsol_mem, LS, J);
 #else
         status = KINDense(kinsol_mem, system_size);
@@ -322,7 +327,10 @@ namespace SUNDIALS
     status = KINGetNumNonlinSolvIters(kinsol_mem, &nniters);
     AssertKINSOL(status);
 
-
+#if DEAL_II_SUNDIALS_VERSION_GTE(3,0,0)
+    SUNMatDestroy(J);
+    SUNLinSolFree(LS);
+#endif
     KINFree(&kinsol_mem);
 
     return (unsigned int) nniters;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.