Add a bunch of overflow checks around malloc()