Skip to content

Commit

Permalink
Fix memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
PunitLodha authored and IshanGrover2004 committed Aug 10, 2024
1 parent 931e6aa commit af42011
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/lib_ccx/ccx_decoders_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ made to reuse, not duplicate, as many functions as possible */

#ifndef DISABLE_RUST
extern int ccxr_process_cc_data(struct lib_cc_decode *dec_ctx, unsigned char *cc_data, int cc_count);
extern void ccxr_flush_decoder(void *dtvcc_rust, struct dtvcc_service_decoder *decoder);
#endif

uint64_t utc_refvalue = UINT64_MAX; /* _UI64_MAX/UINT64_MAX means don't use UNIX, 0 = use current system time as reference, +1 use a specific reference */
Expand Down
2 changes: 1 addition & 1 deletion src/lib_ccx/general_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ int rcwt_loop(struct lib_ccx_ctx *ctx)
#ifndef DISABLE_RUST
ccxr_dtvcc_set_encoder(dec_ctx->dtvcc_rust, enc_ctx);
#else
dec_ctx->dtvcc->encoder = (void *)enc_ctx; // WARN: otherwise cea-708 will not work
dec_ctx->dtvcc->encoder = (void *)enc_ctx; // WARN: otherwise cea-708 will not work
#endif

if (parsebuf[6] == 0 && parsebuf[7] == 2)
Expand Down
2 changes: 1 addition & 1 deletion src/rust/src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ extern "C" fn ccxr_flush_active_decoders(ctx_ptr: *mut lib_cc_decode) {
}
if decoder.cc_count > 0 {
ctx.current_field = 3;
ccxr_flush_decoder(ctx.dtvcc_rust as *mut Dtvcc, Box::into_raw(decoder));
ccxr_flush_decoder(dtvcc_rust, decoder);
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/rust/src/decoder/service_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1202,12 +1202,10 @@ impl dtvcc_service_decoder {
}

/// Flush service decoder
#[no_mangle]
pub extern "C" fn ccxr_flush_decoder(dtvcc_rust: *mut Dtvcc, decoder: *mut dtvcc_service_decoder) {
pub fn ccxr_flush_decoder(dtvcc_rust: &mut Dtvcc, mut decoder: Box<dtvcc_service_decoder>) {
debug!("dtvcc_decoder_flush: Flushing decoder");
let timing = unsafe { &mut *((*dtvcc_rust).timing) };
let encoder = unsafe { &mut *((*dtvcc_rust).encoder) };
let decoder = unsafe { &mut *decoder };
let timing = &mut dtvcc_rust.timing;
let encoder = unsafe { &mut *(dtvcc_rust.encoder) };

let mut screen_content_changed = false;
for i in 0..CCX_DTVCC_MAX_WINDOWS {
Expand Down
10 changes: 8 additions & 2 deletions src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,20 @@ extern "C" fn ccxr_dtvcc_free(dtvcc_rust: *mut Dtvcc) {

// Drop all windows row
window.rows.iter().for_each(|symbol_ptr| unsafe {
symbol_ptr.drop_in_place();
drop(Box::from_raw(*symbol_ptr));
});

window.memory_reserved = 0;
});

unsafe { decoder.tv.drop_in_place() };
unsafe {
drop(Box::from_raw(decoder.tv));
};
}

unsafe {
drop(Box::from_raw(dtvcc));
};
}

#[no_mangle]
Expand Down

0 comments on commit af42011

Please sign in to comment.