@@ -435,23 +435,22 @@ impl H264Encoder {
435435 // (e.g., hardware encoder transient failures, specific MFT implementations).
436436 // This is a known contract violation by certain Media Foundation Transforms.
437437 // We handle this gracefully by skipping the frame instead of panicking.
438- let sample = {
439- let mut output_buffers = [ output_buffer] ;
440- self . transform
441- . ProcessOutput ( 0 , & mut output_buffers, & mut status) ?;
442- output_buffers[ 0 ] . pSample . as_ref ( ) . cloned ( )
443- } ;
438+ let mut output_buffers = [ output_buffer] ;
439+ self . transform . ProcessOutput ( 0 , & mut output_buffers, & mut status) ?;
444440
445- if let Some ( sample) = sample {
441+ // Use the sample directly without cloning to prevent memory leaks
442+ if let Some ( sample) = output_buffers[ 0 ] . pSample . take ( ) {
446443 consecutive_empty_samples = 0 ;
447444 on_sample ( sample) ?;
448445 } else {
449446 consecutive_empty_samples += 1 ;
450447 if consecutive_empty_samples > MAX_CONSECUTIVE_EMPTY_SAMPLES {
451- return Err ( windows:: core:: Error :: new (
452- windows:: core:: HRESULT ( 0 ) ,
453- "Too many consecutive empty samples" ,
454- ) ) ;
448+ return Err (
449+ windows:: core:: Error :: new (
450+ windows:: core:: HRESULT ( 0 ) ,
451+ "Too many consecutive empty samples"
452+ )
453+ ) ;
455454 }
456455 }
457456 }
0 commit comments