main: protect all of the blocks of 'Out of memory' error which might need database reopen to fix