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

Commit 65ce900

Browse files
committed
Fix memory leak
Signed-off-by: Haihao Xiang <[email protected]>
1 parent 851757c commit 65ce900

File tree

5 files changed

+40
-26
lines changed

5 files changed

+40
-26
lines changed

src/gen8_post_processing.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,11 @@ gen8_post_processing_context_finalize(VADriverContextP ctx,
16211621
pp_context->scaling_gpe_context_initialized = 0;
16221622
}
16231623

1624+
if (pp_context->clear_gpe_context_initialized) {
1625+
gen8_gpe_context_destroy(&pp_context->clear_gpe_context);
1626+
pp_context->clear_gpe_context_initialized = 0;
1627+
}
1628+
16241629
if (pp_context->vebox_proc_ctx) {
16251630
gen75_vebox_context_destroy(ctx, pp_context->vebox_proc_ctx);
16261631
pp_context->vebox_proc_ctx = NULL;

src/gen9_hevc_encoder.c

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ static void
411411
gen9_hevc_enc_free_resources(struct encoder_vme_mfc_context *vme_context)
412412
{
413413
struct gen9_hevc_encoder_context *priv_ctx = NULL;
414+
int i;
414415

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

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

427428
i965_free_gpe_resource(&priv_ctx->res_mb_code_surface);
429+
i965_free_gpe_resource(&priv_ctx->res_min_distortion_buffer);
430+
i965_free_gpe_resource(&priv_ctx->res_brc_mb_qp_buffer);
428431

429432
// free VME buffers
430433
i965_free_gpe_resource(&priv_ctx->res_flatness_check_surface);
@@ -446,6 +449,7 @@ gen9_hevc_enc_free_resources(struct encoder_vme_mfc_context *vme_context)
446449
i965_free_gpe_resource(&priv_ctx->res_mvp_index_buffer);
447450
i965_free_gpe_resource(&priv_ctx->res_roi_buffer);
448451
i965_free_gpe_resource(&priv_ctx->res_mb_statistics_buffer);
452+
i965_free_gpe_resource(&priv_ctx->res_slice_map_buffer);
449453

450454
if (priv_ctx->scaled_2x_surface_obj) {
451455
i965_DestroySurfaces(priv_ctx->ctx, &priv_ctx->scaled_2x_surface_id, 1);
@@ -462,6 +466,12 @@ gen9_hevc_enc_free_resources(struct encoder_vme_mfc_context *vme_context)
462466
i965_free_gpe_resource(&priv_ctx->sao_line_buffer);
463467
i965_free_gpe_resource(&priv_ctx->sao_tile_line_buffer);
464468
i965_free_gpe_resource(&priv_ctx->sao_tile_column_buffer);
469+
i965_free_gpe_resource(&priv_ctx->res_brc_pic_states_read_buffer);
470+
471+
for (i = 0; i < GEN9_MAX_MV_TEMPORAL_BUFFERS; i++) {
472+
dri_bo_unreference(priv_ctx->mv_temporal_buffer[i].bo);
473+
priv_ctx->mv_temporal_buffer[i].bo = NULL;
474+
}
465475

466476
priv_ctx->res_inited = 0;
467477
}
@@ -6315,9 +6325,8 @@ gen9_hevc_pak_add_pipe_buf_addr_state(VADriverContextP ctx,
63156325
OUT_BUFFER_MA_TARGET(NULL);
63166326

63176327
for (i = 0; i < GEN9_MAX_REF_SURFACES; i++) {
6318-
if (priv_ctx->reference_surfaces[i].obj_surface &&
6319-
priv_ctx->reference_surfaces[i].obj_surface->bo) {
6320-
bo = priv_ctx->reference_surfaces[i].obj_surface->bo;
6328+
if (priv_ctx->reference_surfaces[i].obj_surface_bo) {
6329+
bo = priv_ctx->reference_surfaces[i].obj_surface_bo;
63216330

63226331
OUT_BUFFER_NMA_REFERENCE(bo);
63236332
} else
@@ -6996,19 +7005,17 @@ gen9_hevc_pak_pipeline_prepare(VADriverContextP ctx,
69967005
priv_state = (struct gen9_hevc_encoder_state *)pak_context->private_enc_state;
69977006
pic_param = (VAEncPictureParameterBufferHEVC *)encode_state->pic_param_ext->buffer;
69987007

6999-
if (priv_ctx->uncompressed_picture_source.obj_surface &&
7000-
priv_ctx->uncompressed_picture_source.obj_surface->bo)
7001-
dri_bo_unreference(priv_ctx->uncompressed_picture_source.obj_surface->bo);
7008+
dri_bo_unreference(priv_ctx->uncompressed_picture_source.obj_surface_bo);
70027009
priv_ctx->uncompressed_picture_source.obj_surface = encode_state->input_yuv_object;
70037010
priv_ctx->uncompressed_picture_source.surface_id = encoder_context->input_yuv_surface;
7004-
dri_bo_reference(priv_ctx->uncompressed_picture_source.obj_surface->bo);
7011+
priv_ctx->uncompressed_picture_source.obj_surface_bo = encode_state->input_yuv_object->bo;
7012+
dri_bo_reference(priv_ctx->uncompressed_picture_source.obj_surface_bo);
70057013

7006-
if (priv_ctx->reconstructed_object.obj_surface &&
7007-
priv_ctx->reconstructed_object.obj_surface->bo)
7008-
dri_bo_unreference(priv_ctx->reconstructed_object.obj_surface->bo);
7014+
dri_bo_unreference(priv_ctx->reconstructed_object.obj_surface_bo);
70097015
priv_ctx->reconstructed_object.obj_surface = encode_state->reconstructed_object;
70107016
priv_ctx->reconstructed_object.surface_id = pic_param->decoded_curr_pic.picture_id;
7011-
dri_bo_reference(priv_ctx->reconstructed_object.obj_surface->bo);
7017+
priv_ctx->reconstructed_object.obj_surface_bo = encode_state->reconstructed_object->bo;
7018+
dri_bo_reference(priv_ctx->reconstructed_object.obj_surface_bo);
70127019

70137020
surface_priv = (struct gen9_hevc_surface_priv *)encode_state->reconstructed_object->private_data;
70147021
if (surface_priv) {
@@ -7023,12 +7030,11 @@ gen9_hevc_pak_pipeline_prepare(VADriverContextP ctx,
70237030
for (i = 0; i < GEN9_MAX_REF_SURFACES; i++) {
70247031
obj_surface = encode_state->reference_objects[i];
70257032
if (obj_surface && obj_surface->bo) {
7026-
if (priv_ctx->reference_surfaces[i].obj_surface &&
7027-
priv_ctx->reference_surfaces[i].obj_surface->bo)
7028-
dri_bo_unreference(priv_ctx->reference_surfaces[i].obj_surface->bo);
7033+
dri_bo_unreference(priv_ctx->reference_surfaces[i].obj_surface_bo);
70297034
priv_ctx->reference_surfaces[i].obj_surface = obj_surface;
70307035
priv_ctx->reference_surfaces[i].surface_id = pic_param->reference_frames[i].picture_id;
7031-
dri_bo_reference(obj_surface->bo);
7036+
priv_ctx->reference_surfaces[i].obj_surface_bo = obj_surface->bo;
7037+
dri_bo_reference(priv_ctx->reference_surfaces[i].obj_surface_bo);
70327038

70337039
surface_priv = (struct gen9_hevc_surface_priv *) obj_surface->private_data;
70347040
if (surface_priv) {
@@ -7283,18 +7289,15 @@ gen9_hevc_pak_context_destroy(void *context)
72837289
dri_bo_unreference(priv_ctx->indirect_pak_bse_object.bo);
72847290
priv_ctx->indirect_pak_bse_object.bo = NULL;
72857291

7286-
if (priv_ctx->uncompressed_picture_source.obj_surface &&
7287-
priv_ctx->uncompressed_picture_source.obj_surface->bo)
7288-
i965_destroy_surface_storage(priv_ctx->uncompressed_picture_source.obj_surface);
7292+
dri_bo_unreference(priv_ctx->uncompressed_picture_source.obj_surface_bo);
7293+
priv_ctx->uncompressed_picture_source.obj_surface_bo = NULL;
7294+
dri_bo_unreference(priv_ctx->reconstructed_object.obj_surface_bo);
7295+
priv_ctx->reconstructed_object.obj_surface_bo = NULL;
72897296

7290-
if (priv_ctx->reconstructed_object.obj_surface &&
7291-
priv_ctx->reconstructed_object.obj_surface->bo)
7292-
i965_destroy_surface_storage(priv_ctx->reconstructed_object.obj_surface);
7293-
7294-
for (i = 0; i < GEN9_MAX_REF_SURFACES; i++)
7295-
if (priv_ctx->reference_surfaces[i].obj_surface &&
7296-
priv_ctx->reference_surfaces[i].obj_surface->bo)
7297-
i965_destroy_surface_storage(priv_ctx->reference_surfaces[i].obj_surface);
7297+
for (i = 0; i < GEN9_MAX_REF_SURFACES; i++) {
7298+
dri_bo_unreference(priv_ctx->reference_surfaces[i].obj_surface_bo);
7299+
priv_ctx->reference_surfaces[i].obj_surface_bo = NULL;
7300+
}
72987301
}
72997302

73007303
#define STATUS_IMPLEMENTATION_START

src/gen9_hevc_encoder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,16 +556,19 @@ struct gen9_hevc_encoder_context {
556556
struct {
557557
struct object_surface *obj_surface;
558558
VASurfaceID surface_id;
559+
dri_bo *obj_surface_bo;
559560
} uncompressed_picture_source;
560561

561562
struct {
562563
struct object_surface *obj_surface;
563564
VASurfaceID surface_id;
565+
dri_bo *obj_surface_bo;
564566
} reconstructed_object;
565567

566568
struct {
567569
struct object_surface *obj_surface;
568570
VASurfaceID surface_id;
571+
dri_bo *obj_surface_bo;
569572
} reference_surfaces[GEN9_MAX_REF_SURFACES];
570573

571574
struct {

src/i965_drv_video.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,6 +2512,7 @@ i965_destroy_context(struct object_heap *heap, struct object_base *obj)
25122512
i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
25132513
i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
25142514
i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2515+
i965_release_buffer_store(&obj_context->codec_state.decode.probability_data);
25152516

25162517
for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
25172518
i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);

src/i965_encoder_vp8.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,8 @@ i965_encoder_vp8_free_surfaces(void **data)
12371237
vp8_surface->scaled_16x_surface_id = VA_INVALID_SURFACE;
12381238
vp8_surface->scaled_16x_surface_obj = NULL;
12391239
}
1240+
1241+
free(vp8_surface);
12401242
}
12411243

12421244
static void

0 commit comments

Comments
 (0)