Commit 33aa9948 authored by wuzhouhui's avatar wuzhouhui Committed by Jim Harris
Browse files

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: default avatarwuzhouhui <wuzhouhui@kingsoft.com>
Reviewed-on: https://review.gerrithub.io/425358


Reviewed-by: default avatarPawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 9eae89f1
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -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);