From deb7d524b6f400950a35ee1538e24239d2cd9874 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Wed, 3 Jan 2018 08:27:23 +0100 Subject: Avoid some VLC leaks --- src/VLCInput.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/VLCInput.cpp b/src/VLCInput.cpp index 837d94f..a215e9f 100644 --- a/src/VLCInput.cpp +++ b/src/VLCInput.cpp @@ -236,11 +236,18 @@ void VLCInput::prepare() m_mp = libvlc_media_player_new_from_media(m); libvlc_media_release(m); + if (!m_mp) { + throw runtime_error("VLC did not return media player"); + } + // Start playing int ret = libvlc_media_player_play(m_mp); if (ret == 0) { libvlc_media_t *media = libvlc_media_player_get_media(m_mp); + if (!media) { + throw runtime_error("VLC did not have a media"); + } libvlc_state_t st; ret = -1; @@ -253,6 +260,8 @@ void VLCInput::prepare() break; } } + + libvlc_media_release(media); } if (ret == -1) { @@ -363,6 +372,12 @@ ssize_t VLCInput::m_read(uint8_t* buf, size_t length) std::this_thread::sleep_for(std::chrono::milliseconds(1)); libvlc_media_t *media = libvlc_media_player_get_media(m_mp); + if (!media) { + fprintf(stderr, "VLC no media\n"); + err = -1; + break; + } + libvlc_state_t st = libvlc_media_get_state(media); if (!(st == libvlc_Opening || st == libvlc_Buffering || @@ -393,6 +408,8 @@ ssize_t VLCInput::m_read(uint8_t* buf, size_t length) } } + libvlc_media_release(media); + if (artist_sz) free(artist_sz); if (title_sz) -- cgit v1.2.3