Skip to content
This repository has been archived by the owner on Jan 31, 2025. It is now read-only.

Commit

Permalink
Fix memory leak
Browse files Browse the repository at this point in the history
Signed-off-by: Haihao Xiang <[email protected]>
  • Loading branch information
xhaihao committed Dec 7, 2018
1 parent 851757c commit 65ce900
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 26 deletions.
5 changes: 5 additions & 0 deletions src/gen8_post_processing.c
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,11 @@ gen8_post_processing_context_finalize(VADriverContextP ctx,
pp_context->scaling_gpe_context_initialized = 0;
}

if (pp_context->clear_gpe_context_initialized) {
gen8_gpe_context_destroy(&pp_context->clear_gpe_context);
pp_context->clear_gpe_context_initialized = 0;
}

if (pp_context->vebox_proc_ctx) {
gen75_vebox_context_destroy(ctx, pp_context->vebox_proc_ctx);
pp_context->vebox_proc_ctx = NULL;
Expand Down
55 changes: 29 additions & 26 deletions src/gen9_hevc_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ static void
gen9_hevc_enc_free_resources(struct encoder_vme_mfc_context *vme_context)
{
struct gen9_hevc_encoder_context *priv_ctx = NULL;
int i;

priv_ctx = (struct gen9_hevc_encoder_context *)vme_context->private_enc_ctx;

Expand All @@ -425,6 +426,8 @@ gen9_hevc_enc_free_resources(struct encoder_vme_mfc_context *vme_context)
i965_free_gpe_resource(&priv_ctx->res_brc_constant_data_buffer);

i965_free_gpe_resource(&priv_ctx->res_mb_code_surface);
i965_free_gpe_resource(&priv_ctx->res_min_distortion_buffer);
i965_free_gpe_resource(&priv_ctx->res_brc_mb_qp_buffer);

// free VME buffers
i965_free_gpe_resource(&priv_ctx->res_flatness_check_surface);
Expand All @@ -446,6 +449,7 @@ gen9_hevc_enc_free_resources(struct encoder_vme_mfc_context *vme_context)
i965_free_gpe_resource(&priv_ctx->res_mvp_index_buffer);
i965_free_gpe_resource(&priv_ctx->res_roi_buffer);
i965_free_gpe_resource(&priv_ctx->res_mb_statistics_buffer);
i965_free_gpe_resource(&priv_ctx->res_slice_map_buffer);

if (priv_ctx->scaled_2x_surface_obj) {
i965_DestroySurfaces(priv_ctx->ctx, &priv_ctx->scaled_2x_surface_id, 1);
Expand All @@ -462,6 +466,12 @@ gen9_hevc_enc_free_resources(struct encoder_vme_mfc_context *vme_context)
i965_free_gpe_resource(&priv_ctx->sao_line_buffer);
i965_free_gpe_resource(&priv_ctx->sao_tile_line_buffer);
i965_free_gpe_resource(&priv_ctx->sao_tile_column_buffer);
i965_free_gpe_resource(&priv_ctx->res_brc_pic_states_read_buffer);

for (i = 0; i < GEN9_MAX_MV_TEMPORAL_BUFFERS; i++) {
dri_bo_unreference(priv_ctx->mv_temporal_buffer[i].bo);
priv_ctx->mv_temporal_buffer[i].bo = NULL;
}

priv_ctx->res_inited = 0;
}
Expand Down Expand Up @@ -6315,9 +6325,8 @@ gen9_hevc_pak_add_pipe_buf_addr_state(VADriverContextP ctx,
OUT_BUFFER_MA_TARGET(NULL);

for (i = 0; i < GEN9_MAX_REF_SURFACES; i++) {
if (priv_ctx->reference_surfaces[i].obj_surface &&
priv_ctx->reference_surfaces[i].obj_surface->bo) {
bo = priv_ctx->reference_surfaces[i].obj_surface->bo;
if (priv_ctx->reference_surfaces[i].obj_surface_bo) {
bo = priv_ctx->reference_surfaces[i].obj_surface_bo;

OUT_BUFFER_NMA_REFERENCE(bo);
} else
Expand Down Expand Up @@ -6996,19 +7005,17 @@ gen9_hevc_pak_pipeline_prepare(VADriverContextP ctx,
priv_state = (struct gen9_hevc_encoder_state *)pak_context->private_enc_state;
pic_param = (VAEncPictureParameterBufferHEVC *)encode_state->pic_param_ext->buffer;

if (priv_ctx->uncompressed_picture_source.obj_surface &&
priv_ctx->uncompressed_picture_source.obj_surface->bo)
dri_bo_unreference(priv_ctx->uncompressed_picture_source.obj_surface->bo);
dri_bo_unreference(priv_ctx->uncompressed_picture_source.obj_surface_bo);
priv_ctx->uncompressed_picture_source.obj_surface = encode_state->input_yuv_object;
priv_ctx->uncompressed_picture_source.surface_id = encoder_context->input_yuv_surface;
dri_bo_reference(priv_ctx->uncompressed_picture_source.obj_surface->bo);
priv_ctx->uncompressed_picture_source.obj_surface_bo = encode_state->input_yuv_object->bo;
dri_bo_reference(priv_ctx->uncompressed_picture_source.obj_surface_bo);

if (priv_ctx->reconstructed_object.obj_surface &&
priv_ctx->reconstructed_object.obj_surface->bo)
dri_bo_unreference(priv_ctx->reconstructed_object.obj_surface->bo);
dri_bo_unreference(priv_ctx->reconstructed_object.obj_surface_bo);
priv_ctx->reconstructed_object.obj_surface = encode_state->reconstructed_object;
priv_ctx->reconstructed_object.surface_id = pic_param->decoded_curr_pic.picture_id;
dri_bo_reference(priv_ctx->reconstructed_object.obj_surface->bo);
priv_ctx->reconstructed_object.obj_surface_bo = encode_state->reconstructed_object->bo;
dri_bo_reference(priv_ctx->reconstructed_object.obj_surface_bo);

surface_priv = (struct gen9_hevc_surface_priv *)encode_state->reconstructed_object->private_data;
if (surface_priv) {
Expand All @@ -7023,12 +7030,11 @@ gen9_hevc_pak_pipeline_prepare(VADriverContextP ctx,
for (i = 0; i < GEN9_MAX_REF_SURFACES; i++) {
obj_surface = encode_state->reference_objects[i];
if (obj_surface && obj_surface->bo) {
if (priv_ctx->reference_surfaces[i].obj_surface &&
priv_ctx->reference_surfaces[i].obj_surface->bo)
dri_bo_unreference(priv_ctx->reference_surfaces[i].obj_surface->bo);
dri_bo_unreference(priv_ctx->reference_surfaces[i].obj_surface_bo);
priv_ctx->reference_surfaces[i].obj_surface = obj_surface;
priv_ctx->reference_surfaces[i].surface_id = pic_param->reference_frames[i].picture_id;
dri_bo_reference(obj_surface->bo);
priv_ctx->reference_surfaces[i].obj_surface_bo = obj_surface->bo;
dri_bo_reference(priv_ctx->reference_surfaces[i].obj_surface_bo);

surface_priv = (struct gen9_hevc_surface_priv *) obj_surface->private_data;
if (surface_priv) {
Expand Down Expand Up @@ -7283,18 +7289,15 @@ gen9_hevc_pak_context_destroy(void *context)
dri_bo_unreference(priv_ctx->indirect_pak_bse_object.bo);
priv_ctx->indirect_pak_bse_object.bo = NULL;

if (priv_ctx->uncompressed_picture_source.obj_surface &&
priv_ctx->uncompressed_picture_source.obj_surface->bo)
i965_destroy_surface_storage(priv_ctx->uncompressed_picture_source.obj_surface);
dri_bo_unreference(priv_ctx->uncompressed_picture_source.obj_surface_bo);
priv_ctx->uncompressed_picture_source.obj_surface_bo = NULL;
dri_bo_unreference(priv_ctx->reconstructed_object.obj_surface_bo);
priv_ctx->reconstructed_object.obj_surface_bo = NULL;

if (priv_ctx->reconstructed_object.obj_surface &&
priv_ctx->reconstructed_object.obj_surface->bo)
i965_destroy_surface_storage(priv_ctx->reconstructed_object.obj_surface);

for (i = 0; i < GEN9_MAX_REF_SURFACES; i++)
if (priv_ctx->reference_surfaces[i].obj_surface &&
priv_ctx->reference_surfaces[i].obj_surface->bo)
i965_destroy_surface_storage(priv_ctx->reference_surfaces[i].obj_surface);
for (i = 0; i < GEN9_MAX_REF_SURFACES; i++) {
dri_bo_unreference(priv_ctx->reference_surfaces[i].obj_surface_bo);
priv_ctx->reference_surfaces[i].obj_surface_bo = NULL;
}
}

#define STATUS_IMPLEMENTATION_START
Expand Down
3 changes: 3 additions & 0 deletions src/gen9_hevc_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -556,16 +556,19 @@ struct gen9_hevc_encoder_context {
struct {
struct object_surface *obj_surface;
VASurfaceID surface_id;
dri_bo *obj_surface_bo;
} uncompressed_picture_source;

struct {
struct object_surface *obj_surface;
VASurfaceID surface_id;
dri_bo *obj_surface_bo;
} reconstructed_object;

struct {
struct object_surface *obj_surface;
VASurfaceID surface_id;
dri_bo *obj_surface_bo;
} reference_surfaces[GEN9_MAX_REF_SURFACES];

struct {
Expand Down
1 change: 1 addition & 0 deletions src/i965_drv_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -2512,6 +2512,7 @@ i965_destroy_context(struct object_heap *heap, struct object_base *obj)
i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
i965_release_buffer_store(&obj_context->codec_state.decode.probability_data);

for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
Expand Down
2 changes: 2 additions & 0 deletions src/i965_encoder_vp8.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,8 @@ i965_encoder_vp8_free_surfaces(void **data)
vp8_surface->scaled_16x_surface_id = VA_INVALID_SURFACE;
vp8_surface->scaled_16x_surface_obj = NULL;
}

free(vp8_surface);
}

static void
Expand Down

0 comments on commit 65ce900

Please sign in to comment.