0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00

obs-ffmpeg: Fix memory leaks if replay buffer failed

When releasing a darray mux_packets at error, contents of mux_packets
are not released. It causes memory leaks if error occurs during saving
the replay buffer to a file.
This commit is contained in:
Norihiro Kamae 2021-12-01 12:26:33 +09:00 committed by Jim
parent c1b87e70ef
commit f8bcc190e2

View File

@ -66,6 +66,8 @@ static void ffmpeg_mux_destroy(void *data)
replay_buffer_clear(stream); replay_buffer_clear(stream);
if (stream->mux_thread_joinable) if (stream->mux_thread_joinable)
pthread_join(stream->mux_thread, NULL); pthread_join(stream->mux_thread, NULL);
for (size_t i = 0; i < stream->mux_packets.num; i++)
obs_encoder_packet_release(&stream->mux_packets.array[i]);
da_free(stream->mux_packets); da_free(stream->mux_packets);
circlebuf_free(&stream->packets); circlebuf_free(&stream->packets);
@ -847,6 +849,11 @@ static void *replay_buffer_mux_thread(void *data)
error: error:
os_process_pipe_destroy(stream->pipe); os_process_pipe_destroy(stream->pipe);
stream->pipe = NULL; stream->pipe = NULL;
if (error) {
for (size_t i = 0; i < stream->mux_packets.num; i++)
obs_encoder_packet_release(
&stream->mux_packets.array[i]);
}
da_free(stream->mux_packets); da_free(stream->mux_packets);
os_atomic_set_bool(&stream->muxing, false); os_atomic_set_bool(&stream->muxing, false);
@ -934,6 +941,10 @@ static void replay_buffer_save(struct ffmpeg_muxer *stream)
stream->mux_thread_joinable = pthread_create(&stream->mux_thread, NULL, stream->mux_thread_joinable = pthread_create(&stream->mux_thread, NULL,
replay_buffer_mux_thread, replay_buffer_mux_thread,
stream) == 0; stream) == 0;
if (!stream->mux_thread_joinable) {
warn("Failed to create muxer thread");
os_atomic_set_bool(&stream->muxing, false);
}
} }
static void deactivate_replay_buffer(struct ffmpeg_muxer *stream, int code) static void deactivate_replay_buffer(struct ffmpeg_muxer *stream, int code)