Fixing memory leak on rpc and flow