Fixed memory leak.
Fixed mmap error check.
Add state types to client api.