Few coverity fixes

A couple of memleaks and a double close in rpc.