fdo#78598 avoid use of invalidated pointers

Change-Id: Ib81f79da696b5e8002f5a2ddcf160903231dc3f1
(cherry picked from commit 6b127d40c7d57745bc602d9ff7914392f9d3b92b)
Reviewed-on: https://gerrit.libreoffice.org/10421
Reviewed-by: Björn Michaelsen <bjoern.michaelsen@canonical.com>
Tested-by: Björn Michaelsen <bjoern.michaelsen@canonical.com>