# Finalize() problem in my own code's adapter

**URL:** <https://precice.discourse.group/t/finalize-problem-in-my-own-codes-adapter/1869>\
**Category:** Using preCICE\
**Tags:** fortran\
**Created:** [April 3, 2024, 7:33am UTC](https://precice.discourse.group/t/finalize-problem-in-my-own-codes-adapter/1869 "2024-04-03T07:33:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gong\_CHEN](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/gong_chen/32/2212_2.png) [@Gong\_CHEN](https://precice.discourse.group/u/Gong_CHEN)\
**Post date:** [April 3, 2024, 7:33am UTC](https://precice.discourse.group/t/finalize-problem-in-my-own-codes-adapter/1869/1 "2024-04-03T07:33:43Z")

</div>

Hi preCICE developer and user~

I just finished my FEM code’s adapter, but problem happended in the final step, which is finalizing the preCICE.

My code is written by fortran language, so in finalize subroutine, as show:

```
subroutine finalize()
  implicit none
  INTEGER :: isOngoing

  call precicef_is_coupling_ongoing(isOngoing)

  if ( preciceInitialized_ .and. isOngoing == 0 ) then
    call precicef_finalize()
    preciceInitialized_ = .false.
    ! Delete the solver interface and all the related data
    call teardown()
  else
    write(msg,'(a)') '* Could not finalize preCICE. Error!!!'
    call printf( msg = msg ); mfid = Message_ID; call printf(mfid, msg)
  end if

end subroutine finalize

```

And I test my adapter with solverdummy. I found out that after calling `call precicef_finalize()`, error shows:

```
* The coupling completed.
* Finalizing the preCICE solver interface...
(0) 15:19:22 [impl::ParticipantImpl]:1555 in closeCommunicationChannels: Close communication channels
malloc(): largebin double linked list corrupted (bk)
forrtl: error (76): Abort trap signal
Image PC Routine Line Source             
libpthread-2.31.s 00007F0D9A14F420 Unknown Unknown Unknown
libc-2.31.so 00007F0D99F8A00B gsignal Unknown Unknown
libc-2.31.so 00007F0D99F69859 abort Unknown Unknown
libc-2.31.so 00007F0D99FD426E Unknown Unknown Unknown
libc-2.31.so 00007F0D99FDC2FC Unknown Unknown Unknown
libc-2.31.so 00007F0D99FDC94C Unknown Unknown Unknown
libc-2.31.so 00007F0D99FDDE8B Unknown Unknown Unknown
libc-2.31.so 00007F0D99FE188D Unknown Unknown Unknown
libpthread-2.31.s 00007F0D9A14362F Unknown Unknown Unknown
libc-2.31.so 00007F0D9A066353 clone Unknown Unknown

```

The info seems relevant to double-linked list in preCICE, so I don’t know how to solve it, has anyone encounter similar problem?

Thank you !!!

---

<div class="post-metadata">

**Author:** ![Gong\_CHEN](https://yyz2.discourse-cdn.com/free1/user_avatar/precice.discourse.group/gong_chen/32/2212_2.png) [@Gong\_CHEN](https://precice.discourse.group/u/Gong_CHEN)\
**Post date:** [April 9, 2024, 8:30am UTC](https://precice.discourse.group/t/finalize-problem-in-my-own-codes-adapter/1869/2 "2024-04-09T08:30:02Z")

</div>

I think I may have solved the problem, maybe related to the data buffer.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/precice/original/1X/67d2a5fa6f80e597e2267ff17fa8c1673cd11caa.svg) [@system](https://precice.discourse.group/u/system)\
**Post date:** [May 6, 2024, 12:35pm UTC](https://precice.discourse.group/t/finalize-problem-in-my-own-codes-adapter/1869/3 "2024-05-06T12:35:02Z")

</div>

Closed on May 6, 2024, 12:35pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
