phoboslab / pl_mpeg

Single file C library for decoding MPEG1 Video and MP2 Audio
799 stars 58 forks source link

Fix memory issue of mode `PLM_BUFFER_MODE_RING` #27

Closed CW-B-W closed 2 years ago

CW-B-W commented 2 years ago

video_buffer keep calling realloc() and keep expanding its memory usage:

In plm_buffer_has_start_code(), the discard_read_bytes is temporarily set to FALSE.

But when it goes all the way to plm_buffer_has(), it will trigger the the load_callback(), which is set to plm_read_video_packet() in plm_init_decoders().

Then plm_buffer_write() will eventually be called when discard_read_bytes is set to FALSE. Finally it causes the video_buffer to keep expanding.

phoboslab commented 2 years ago

Good catch. Thank you!