Replaced mallocForeign with alloca