check TRG_HasMasterPage before TRG_GetMasterPage

bff + valgrind

Change-Id: Ie08ddfe06dc0850cf44955cc9f9079b3856b19e3
(cherry picked from commit fad62d928a4b4cd3aa96e16d7ab8f8db0331b8c0)
Reviewed-on: https://gerrit.libreoffice.org/10954
Reviewed-by: David Tardon <dtardon@redhat.com>
Tested-by: David Tardon <dtardon@redhat.com>