check TRG_HasMasterPage before TRG_GetMasterPage

bff + valgrind

Change-Id: Ie08ddfe06dc0850cf44955cc9f9079b3856b19e3