added malloc check