fdo#39440 reduce scope of local variables

This addresses some cppcheck warnings.

Change-Id: I57f336c6ab3c418eac82397edeadecb4c1b168a7
Reviewed-on: https://gerrit.libreoffice.org/13495
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>