diff --git a/src/context.c b/src/context.c index 812f8e9..230837d 100644 --- a/src/context.c +++ b/src/context.c @@ -96,12 +96,19 @@ VAStatus SunxiCedrusCreateContext(VADriverContextP context, goto error; } + /* + * The surface_ids array has been allocated by the caller and + * we don't have any indication wrt its life time. Let's make sure + * its life span is under our control. + */ ids = malloc(surfaces_count * sizeof(VASurfaceID)); if (ids == NULL) { status = VA_STATUS_ERROR_ALLOCATION_FAILED; goto error; } + memcpy(ids, surfaces_ids, surfaces_count * sizeof(VASurfaceID)); + for (i = 0; i < surfaces_count; i++) { surface_object = SURFACE(surfaces_ids[i]); if (surface_object == NULL) { @@ -125,8 +132,6 @@ VAStatus SunxiCedrusCreateContext(VADriverContextP context, surface_object->destination_index = i; surface_object->source_data = source_data; surface_object->source_size = length; - - ids[i] = surfaces_ids[i]; } rc = v4l2_set_stream(driver_data->video_fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, true);