improved allocation error handlings.
Merge pull request #97 from cubicdaiya/feature/alloc_error_check

improved allocation error handlings.