Commit ebfca1b4 authored by Dave Stevenson's avatar Dave Stevenson Committed by popcornmix
Browse files

staging: mmal-vchiq: Fix memory leak in error path



On error, vchiq_mmal_component_init could leave the
event context allocated for ports.
Clean them up in the error path.

Signed-off-by: default avatarDave Stevenson <dave.stevenson@raspberrypi.org>
parent 365ab793
Loading
Loading
Loading
Loading
+19 −8
Original line number Diff line number Diff line
@@ -1848,9 +1848,26 @@ static void free_event_context(struct vchiq_mmal_port *port)
{
	struct mmal_msg_context *ctx = port->event_context;

	if (!ctx)
		return;

	kfree(ctx->u.bulk.buffer->buffer);
	kfree(ctx->u.bulk.buffer);
	release_msg_context(ctx);
	port->event_context = NULL;
}

static void release_all_event_contexts(struct vchiq_mmal_component *component)
{
	int idx;

	for (idx = 0; idx < component->inputs; idx++)
		free_event_context(&component->input[idx]);
	for (idx = 0; idx < component->outputs; idx++)
		free_event_context(&component->output[idx]);
	for (idx = 0; idx < component->clocks; idx++)
		free_event_context(&component->clock[idx]);
	free_event_context(&component->control);
}

/* Initialise a mmal component and its ports
@@ -1948,6 +1965,7 @@ int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,

release_component:
	destroy_component(instance, component);
	release_all_event_contexts(component);
unlock:
	if (component)
		component->in_use = 0;
@@ -1975,14 +1993,7 @@ int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,

	component->in_use = 0;

	for (idx = 0; idx < component->inputs; idx++)
		free_event_context(&component->input[idx]);
	for (idx = 0; idx < component->outputs; idx++)
		free_event_context(&component->output[idx]);
	for (idx = 0; idx < component->clocks; idx++)
		free_event_context(&component->clock[idx]);

	free_event_context(&component->control);
	release_all_event_contexts(component);

	mutex_unlock(&instance->vchiq_mutex);