vhost: rpc: fix memory leak of spdk_rpc_get_vhost_controllers
spdk_rpc_get_vhost_controllers() forgot to free memory of w when ctx allocation failed. Defering the invoke of spdk_jsonrpc_begin_result(), so we can handle the failure conveniently. Change-Id: I223f5b9a918b068922d5a68c8d688331ebf90e42 Signed-off-by: wuzhouhui <wuzhouhui@kingsoft.com> Reviewed-on: https://review.gerrithub.io/425358 Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
9eae89f10c
commit
33aa994855
@ -501,13 +501,6 @@ spdk_rpc_get_vhost_controllers(struct spdk_jsonrpc_request *request,
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
spdk_json_write_array_begin(w);
|
||||
|
||||
ctx = calloc(1, sizeof(*ctx));
|
||||
if (ctx == NULL) {
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
||||
@ -515,6 +508,14 @@ spdk_rpc_get_vhost_controllers(struct spdk_jsonrpc_request *request,
|
||||
return;
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
if (w == NULL) {
|
||||
free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
spdk_json_write_array_begin(w);
|
||||
|
||||
ctx->w = w;
|
||||
ctx->request = request;
|
||||
spdk_vhost_call_external_event_foreach(spdk_rpc_get_vhost_controllers_cb, ctx);
|
||||
|
Loading…
x
Reference in New Issue
Block a user