office-gobmx/include/unotest
Mike Kaganski 8cce131dcc Avoid crash in shutdown when accessing already destroyed BASIC_DLL
... in ImplRepository::~ImplRepository.

Running on Windows:
make UITest_manual_tests UITEST_TEST_NAME=calc.ManualCalcTests.test_cell_recalc

fails:

  ...
  Execution time for calc.ManualCalcTests.test_cell_recalc: 8.876
  tearDown: calling terminate()...
  ...done
  ERROR

  ======================================================================
  ERROR: test_cell_recalc (calc.ManualCalcTests)
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File "C:\lo\src\core\uitest\uitest\framework.py", line 46, in tearDown
      self.connection.tearDown()
    File "C:\lo\src\core\uitest\libreoffice\connection.py", line 178, in tearDown
      self.connection.tearDown()
    File "C:\lo\src\core\uitest\libreoffice\connection.py", line 138, in tearDown
      raise Exception("Exit status indicates failure: " + str(ret))
  Exception: Exit status indicates failure: 3221225477

  ----------------------------------------------------------------------
  Ran 1 test in 131.616s

  FAILED (errors=1)
  Tests run: 1
  Tests failed: 0
  Tests errors: 1
  Tests skipped: 0

The call stack at the point of failure is

  sblo.dll!std::unique_ptr<SbxAppData,std::default_delete<SbxAppData>>::operator*() Line 1886
  sblo.dll!GetSbxData_Impl() Line 110
  sblo.dll!SbxBase::RemoveFactory(const SbxFactory * pFac) Line 122
  sblo.dll!StarBASIC::~StarBASIC() Line 964
  sblo.dll!StarBASIC::`vbase destructor'()
  sblo.dll!StarBASIC::`vector deleting destructor'(unsigned int)
  tllo.dll!SvRefBase::ReleaseRef() Line 163
  sblo.dll!tools::SvRef<StarBASIC>::~SvRef<StarBASIC>() Line 56
  sblo.dll!BasicLibInfo::~BasicLibInfo()
  sblo.dll!BasicLibInfo::`scalar deleting destructor'(unsigned int)
  sblo.dll!std::default_delete<BasicLibInfo>::operator()(BasicLibInfo * _Ptr) Line 1765
  sblo.dll!std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>>::~unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>>() Line 1875
  sblo.dll!std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>>::`scalar deleting destructor'(unsigned int)
  sblo.dll!std::_Default_allocator_traits<std::allocator<std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>>>>::destroy<std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>>>(std::allocator<std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>>> & __formal, std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>> * const _Ptr) Line 677
  sblo.dll!std::_Destroy_range<std::allocator<std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>>>>(std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>> * _First, std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>> * const _Last, std::allocator<std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>>> & _Al) Line 951
  sblo.dll!std::vector<std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>>,std::allocator<std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>>>>::_Destroy(std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>> * _First, std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>> * _Last) Line 1616
  sblo.dll!std::vector<std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>>,std::allocator<std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>>>>::_Tidy() Line 1698
  sblo.dll!std::vector<std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>>,std::allocator<std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>>>>::~vector<std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>>,std::allocator<std::unique_ptr<BasicLibInfo,std::default_delete<BasicLibInfo>>>>() Line 674
  sblo.dll!BasicManagerImpl::~BasicManagerImpl()
  sblo.dll!BasicManagerImpl::`scalar deleting destructor'(unsigned int)
  sblo.dll!std::default_delete<BasicManagerImpl>::operator()(BasicManagerImpl * _Ptr) Line 1765
  sblo.dll!std::unique_ptr<BasicManagerImpl,std::default_delete<BasicManagerImpl>>::~unique_ptr<BasicManagerImpl,std::default_delete<BasicManagerImpl>>() Line 1875
  sblo.dll!BasicManager::~BasicManager() Line 824
  sblo.dll!BasicManager::`vector deleting destructor'(unsigned int)
  sblo.dll!std::default_delete<BasicManager>::operator()(BasicManager * _Ptr) Line 1765
  sblo.dll!std::unique_ptr<BasicManager,std::default_delete<BasicManager>>::~unique_ptr<BasicManager,std::default_delete<BasicManager>>() Line 1875
  sblo.dll!std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>::~pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>()
  sblo.dll!std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>::`scalar deleting destructor'(unsigned int)
  sblo.dll!std::_Default_allocator_traits<std::allocator<std::_Tree_node<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>,void *>>>::destroy<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>>(std::allocator<std::_Tree_node<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>,void *>> & __formal, std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>> * const _Ptr) Line 677
  sblo.dll!std::_Tree_node<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>,void *>::_Freenode<std::allocator<std::_Tree_node<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>,void *>>>(std::allocator<std::_Tree_node<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>,void *>> & _Al, std::_Tree_node<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>,void *> * _Ptr) Line 379
  sblo.dll!std::_Tree<std::_Tmap_traits<com::sun::uno::Reference<com::sun::uno::XInterface>,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>,std::less<com::sun::uno::Reference<com::sun::uno::XInterface>>,std::allocator<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>>,0>>::_Erase_unchecked(std::_Tree_unchecked_const_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>>>,std::_Iterator_base0> _Where) Line 1389
  sblo.dll!std::_Tree<std::_Tmap_traits<com::sun::uno::Reference<com::sun::uno::XInterface>,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>,std::less<com::sun::uno::Reference<com::sun::uno::XInterface>>,std::allocator<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>>,0>>::erase<std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>>>>,void>(std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>>>> _Where) Line 1417
  sblo.dll!basic::ImplRepository::Notify(SfxBroadcaster & _rBC, const SfxHint & _rHint) Line 580
  svllo.dll!SfxBroadcaster::Broadcast(const SfxHint & rHint) Line 50
  sblo.dll!BasicManager::~BasicManager() Line 823
  sblo.dll!BasicManager::`vector deleting destructor'(unsigned int)
  sblo.dll!std::default_delete<BasicManager>::operator()(BasicManager * _Ptr) Line 1765
  sblo.dll!std::unique_ptr<BasicManager,std::default_delete<BasicManager>>::~unique_ptr<BasicManager,std::default_delete<BasicManager>>() Line 1875
  sblo.dll!std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>::~pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>()
  sblo.dll!std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>::`scalar deleting destructor'(unsigned int)
  sblo.dll!std::_Default_allocator_traits<std::allocator<std::_Tree_node<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>,void *>>>::destroy<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>>(std::allocator<std::_Tree_node<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>,void *>> & __formal, std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>> * const _Ptr) Line 677
  sblo.dll!std::_Tree_node<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>,void *>::_Freenode<std::allocator<std::_Tree_node<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>,void *>>>(std::allocator<std::_Tree_node<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>,void *>> & _Al, std::_Tree_node<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>,void *> * _Ptr) Line 379
  sblo.dll!std::_Tree_val<std::_Tree_simple_types<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>>>::_Erase_tree<std::allocator<std::_Tree_node<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>,void *>>>(std::allocator<std::_Tree_node<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>,void *>> & _Al, std::_Tree_node<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>,void *> * _Rootnode) Line 745
  sblo.dll!std::_Tree_val<std::_Tree_simple_types<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>>>::_Erase_head<std::allocator<std::_Tree_node<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>,void *>>>(std::allocator<std::_Tree_node<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>,void *>> & _Al) Line 753
  sblo.dll!std::_Tree<std::_Tmap_traits<com::sun::uno::Reference<com::sun::uno::XInterface>,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>,std::less<com::sun::uno::Reference<com::sun::uno::XInterface>>,std::allocator<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>>,0>>::~_Tree<std::_Tmap_traits<com::sun::uno::Reference<com::sun::uno::XInterface>,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>,std::less<com::sun::uno::Reference<com::sun::uno::XInterface>>,std::allocator<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>>,0>>() Line 1191
  sblo.dll!std::map<com::sun::uno::Reference<com::sun::uno::XInterface>,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>,std::less<com::sun::uno::Reference<com::sun::uno::XInterface>>,std::allocator<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>>>::~map<com::sun::uno::Reference<com::sun::uno::XInterface>,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>,std::less<com::sun::uno::Reference<com::sun::uno::XInterface>>,std::allocator<std::pair<com::sun::uno::Reference<com::sun::uno::XInterface> const ,std::unique_ptr<BasicManager,std::default_delete<BasicManager>>>>>()
  sblo.dll!basic::ImplRepository::~ImplRepository()
  sblo.dll!`basic::ImplRepository::Instance'::`2'::`dynamic atexit destructor for 'repository''()
  ucrtbased.dll!_execute_onexit_table::__l2::<lambda>() Line 206
  ucrtbased.dll!__crt_seh_guarded_call<int>::operator()<void <lambda>(void),int <lambda>(void) &,void <lambda>(void)>(__acrt_lock_and_call::__l2::void <lambda>(void) && setup, _execute_onexit_table::__l2::int <lambda>(void) & action, __acrt_lock_and_call::__l2::void <lambda>(void) && cleanup) Line 204
  ucrtbased.dll!__acrt_lock_and_call<int <lambda>(void)>(const __acrt_lock_id lock_id, _execute_onexit_table::__l2::int <lambda>(void) && action) Line 975
  ucrtbased.dll!_execute_onexit_table(_onexit_table_t * table) Line 231
  sblo.dll!__scrt_dllmain_uninitialize_c() Line 399
  sblo.dll!dllmain_crt_process_detach(const bool is_terminating) Line 182
  sblo.dll!dllmain_crt_dispatch(HINSTANCE__ * const instance, const unsigned long reason, void * const reserved) Line 220
  sblo.dll!dllmain_dispatch(HINSTANCE__ * const instance, const unsigned long reason, void * const reserved) Line 293
  sblo.dll!_DllMainCRTStartup(HINSTANCE__ * const instance, const unsigned long reason, void * const reserved) Line 335
  ntdll.dll!LdrpCallInitRoutine()
  ntdll.dll!LdrShutdownProcess()
  ntdll.dll!RtlExitUserProcess()
  kernel32.dll!ExitProcessImplementation()
  ucrtbased.dll!exit_or_terminate_process(const unsigned int return_code) Line 144
  ucrtbased.dll!common_exit(const int return_code, const _crt_exit_cleanup_mode cleanup_mode, const _crt_exit_return_mode return_mode) Line 282
  ucrtbased.dll!exit(int return_code) Line 294
  soffice.bin!__scrt_common_main_seh() Line 297
  soffice.bin!__scrt_common_main() Line 331
  soffice.bin!mainCRTStartup() Line 17
  kernel32.dll!BaseThreadInitThunk()
  ntdll.dll!RtlUserThreadStart()

Two problems here:
1. Deleting a function-local static ImplRepository object happens after
BASIC_DLL destruction either in SfxApplication::~SfxApplication or in
MacroSnippet::~MacroSnippet, so BasicManager dtor indirectly trying to
access BASIC_DLL segfaults.
2. Implicit clearing of m_aStore in ImplRepository dtor calls dtors of
owned BasicManager objects, which in turn notify parent ImplRepository,
which again deletes the objects.

This change limits lifetime of ImplRepository object with SbxAppData
in BASIC_DLL, and avoids "owned BasicManager is deleting" notifications
in its dtor.

In dbaccess_complex test, ODatabaseContext accesses ImplRepository
instance independently of SfxAppData_Impl lifetime: the latter is
created before the former is created (and accesses ImplRepository
instance first time), and destroyed before the former is destroyed
(and accesses ImplRepository last time). So BASIC_DLL lifetime made
ref-counted, to allow correct sharing of common instance between
objects with independent lifetime.

See also commit 3ebf6a090b.

Change-Id: I2ca36a87ddaf669557b3c3c7678e3d74aae66cce
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85892
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Mike Kaganski <mike.kaganski@collabora.com>
2019-12-29 15:46:16 +01:00
..
detail
assertion_traits.hxx
bootstrapfixturebase.hxx
directories.hxx
filters-test.hxx
gettestargument.hxx
macros_test.hxx
officeconnection.hxx
toabsolutefileurl.hxx