Misc fixes to check OOM
Merge pull request #1787 from hardening/oom_checks2

Misc fixes to check OOM