Skip to content

Fix crash in destructor when using libcxx (Clang STL, FreeBSD)

Adriaan de Groot requested to merge work/adridg/fix-libcxx-crash into master

This code crashes in the destructor of LdapClient on FreeBSD. The crash is visible to uses who

  • start KOrganizer
  • click the "New Event" button

The underlying issue is a lot like the one described in https://blogs.kde.org/2021/02/20/uniqueptr-difference-between-libstdc-and-libc-crashes-your-application There is a convoluted call-chain on destruction of LdapClient:

  • ~LdapClient
  • ~std::unique_ptr
  • ~LdapClientPrivate
  • LdapClient::cancelQuery
  • (accesses to members of LdapClientPrivate d)

With libcxx, the pointer in d is already set to nullptr and SEGV happens. It is UB, anyway, since the destructor body for LdapClient has already run.

The fix moves the implementation of cancelQuery() into the private class. This means that the LdapClient class does a little less poking-and-prodding in the private class, but also cuts out the call-from-private-back-to-destroyed- owning-LdapClient, fixing the SEGV and UB.

Merge request reports

Loading