added malloc check, some trivial change

if malloc failes, I think we'ed better exit...anyway