etc/search: handle malloc failures and fix build warnings