Fix some memory leaks, potential errors.

Fix a couple of memory leaks in tests.

Fix a potential case that length could be zero.

Bug: 23762183

Test: Ran unit tests, then ran valgrind on unit tests and verified no leaks.
Change-Id: I5f7602aa0204db0488a8e305250658cdb6e977d0
3 files changed