From: hschang Date: Mon, 21 Nov 2016 07:08:04 +0000 (+0900) Subject: Avoid to use invalid file descriptor. X-Git-Url: http://code.vuplus.com/gitweb/?p=vuplus_dvbapp;a=commitdiff_plain;h=62fa52e2f0de554aeebc08d081c225466b7d82b8 Avoid to use invalid file descriptor. --- diff --git a/lib/dvb/demux.cpp b/lib/dvb/demux.cpp index 0d03927..0cebc70 100644 --- a/lib/dvb/demux.cpp +++ b/lib/dvb/demux.cpp @@ -98,6 +98,7 @@ RESULT eDVBDemux::setSourceFrontend(int fenum) { #if HAVE_DVB_API_VERSION >= 3 int fd = openDemux(); + if (fd < 0) return -1; int n = DMX_SOURCE_FRONT0 + fenum; int res = ::ioctl(fd, DMX_SET_SOURCE, &n); if (res) @@ -114,6 +115,7 @@ RESULT eDVBDemux::setSourcePVR(int pvrnum) { #if HAVE_DVB_API_VERSION >= 3 int fd = openDemux(); + if (fd < 0) return -1; int n = DMX_SOURCE_DVR0 + pvrnum; int res = ::ioctl(fd, DMX_SET_SOURCE, &n); source = -1; @@ -584,6 +586,7 @@ RESULT eDVBTSRecorder::start() { eDebug("DMX_SET_PES_FILTER: %m"); ::close(m_source_fd); + m_source_fd = -1; return -3; } @@ -677,25 +680,33 @@ RESULT eDVBTSRecorder::stop() #if HAVE_DVB_API_VERSION >= 5 /* workaround for record thread stop */ - if (::ioctl(m_source_fd, DMX_STOP) < 0) - perror("DMX_STOP"); - else - state &= ~1; + if (m_source_fd >= 0) + { + if (::ioctl(m_source_fd, DMX_STOP) < 0) + perror("DMX_STOP"); + else + state &= ~1; - if (::close(m_source_fd) < 0) - perror("close"); - else - state &= ~2; + if (::close(m_source_fd) < 0) + perror("close"); + else + state &= ~2; + m_source_fd = -1; + } #endif m_thread->stop(); if (state & 3) - ::close(m_source_fd); + { + if (m_source_fd >= 0) + { + ::close(m_source_fd); + m_source_fd = -1; + } + } m_running = 0; - m_source_fd = -1; - m_thread->stopSaveMetaInformation(); return 0; } diff --git a/lib/dvb/dvb.cpp b/lib/dvb/dvb.cpp index 72d4687..0c36b7c 100755 --- a/lib/dvb/dvb.cpp +++ b/lib/dvb/dvb.cpp @@ -2071,7 +2071,10 @@ void eDVBChannel::stopSource() m_pvr_thread = 0; } if (m_pvr_fd_dst >= 0) + { ::close(m_pvr_fd_dst); + m_pvr_fd_dst = -1; + } ePtr d; m_tstools.setSource(d); }