fix memory leak warnings and rpc test