Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

obs-outputs: Fix memory leak of packet #11715

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions plugins/obs-outputs/rtmp-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,10 @@ static int send_packet(struct rtmp_stream *stream, struct encoder_packet *packet
{
uint8_t *data;
size_t size;
int ret = 0;
int ret = -1;

if (handle_socket_read(stream))
return -1;
goto end;

flv_packet_mux(packet, is_header ? 0 : stream->start_dts_offset, &data, &size, is_header);

Expand All @@ -414,12 +414,14 @@ static int send_packet(struct rtmp_stream *stream, struct encoder_packet *packet
ret = RTMP_Write(&stream->rtmp, (char *)data, (int)size, 0);
bfree(data);

stream->total_bytes_sent += size;

end:
if (is_header)
bfree(packet->data);
else
obs_encoder_packet_release(packet);

stream->total_bytes_sent += size;
return ret;
}

Expand All @@ -428,10 +430,10 @@ static int send_packet_ex(struct rtmp_stream *stream, struct encoder_packet *pac
{
uint8_t *data;
size_t size = 0;
int ret = 0;
int ret = -1;

if (handle_socket_read(stream))
return -1;
goto end;

if (is_header) {
flv_packet_start(packet, stream->video_codec[idx], &data, &size, idx);
Expand All @@ -448,23 +450,25 @@ static int send_packet_ex(struct rtmp_stream *stream, struct encoder_packet *pac
ret = RTMP_Write(&stream->rtmp, (char *)data, (int)size, 0);
bfree(data);

stream->total_bytes_sent += size;

end:
if (is_header || is_footer) // manually created packets
bfree(packet->data);
else
obs_encoder_packet_release(packet);

stream->total_bytes_sent += size;
return ret;
}

static int send_audio_packet_ex(struct rtmp_stream *stream, struct encoder_packet *packet, bool is_header, size_t idx)
{
uint8_t *data;
size_t size = 0;
int ret = 0;
int ret = -1;

if (handle_socket_read(stream))
return -1;
goto end;

if (is_header) {
flv_packet_audio_start(packet, stream->audio_codec[idx], &data, &size, idx);
Expand All @@ -475,6 +479,7 @@ static int send_audio_packet_ex(struct rtmp_stream *stream, struct encoder_packe
ret = RTMP_Write(&stream->rtmp, (char *)data, (int)size, 0);
bfree(data);

end:
if (is_header)
bfree(packet->data);
else
Expand Down
Loading