avoid use of ref. to possibly deleted object

Change-Id: If5977b280fed8d8b053f59852d3984a59ce61a69
(cherry picked from commit ce5cc7afb0f1c99237d04e0c754527c725d8491c)
Reviewed-on: https://gerrit.libreoffice.org/11832
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
(cherry picked from commit 53fd61faef7100e4609076a517e349e3b2ff2109)
Reviewed-on: https://gerrit.libreoffice.org/11858
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>