Fix the coverity issues

This PR is to resolve issues raised by coverity.

BUG=XWALK-2928
The problem in this method is that `ret_val` was a raw pointer and its previous value was leaking. You have not fixed the leak at all. Try making it a `scoped_ptr` from the beginning instead.