From b0cea9ce242f0914691f052215fe73a510c0ed18 Mon Sep 17 00:00:00 2001 From: James Zern Date: Mon, 1 May 2017 15:17:30 -0700 Subject: [PATCH] Add(Audio|Video)Track: fix memory leak on failure quiets a static analysis warning Change-Id: Iaa6909e94deae81ace3e65f37ab746d72031620f --- mkvmuxer/mkvmuxer.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mkvmuxer/mkvmuxer.cc b/mkvmuxer/mkvmuxer.cc index b7ab131..9bf1924 100644 --- a/mkvmuxer/mkvmuxer.cc +++ b/mkvmuxer/mkvmuxer.cc @@ -3361,7 +3361,10 @@ uint64_t Segment::AddVideoTrack(int32_t width, int32_t height, int32_t number) { track->set_width(width); track->set_height(height); - tracks_.AddTrack(track, number); + if (!tracks_.AddTrack(track, number)) { + delete track; + return 0; + } has_video_ = true; return track->number(); @@ -3401,7 +3404,10 @@ uint64_t Segment::AddAudioTrack(int32_t sample_rate, int32_t channels, track->set_sample_rate(sample_rate); track->set_channels(channels); - tracks_.AddTrack(track, number); + if (!tracks_.AddTrack(track, number)) { + delete track; + return 0; + } return track->number(); }