[r7]
- add unit-test.
[libks]
- fix memory leak.
- fix part of memory leak.