Ticket #6223: mythtv-fixDeleteCachedTable.diff

File mythtv-fixDeleteCachedTable.diff, 7.2 KB (added by mortalmatt, 15 years ago)
  • mythtv/libs/libmythtv/mpeg/atscstreamdata.cpp

    The following fixes a crash in ScanStreamData::DeleteCachedTable().
    
    The first call to ATSCStreamData::DeleteCachedTable() can delete the
    PSIPTable object. The remaining code will then operate on an invalid object
    resulting in undefined behaviour and segmentation faults.
    
    The fix introduces a boolean return value for all DeleteCacheTable() methods
    which indicates where an object got deleted (true) or not (false). This way
    the caller at least knows what happened and can react properly.
    
    Signed-Off-By: Matthias Dahl <devel@mortal-soul.de>
    
    diff -u a/mythtv/libs/libmythtv/mpeg/atscstreamdata.cpp b/mythtv/libs/libmythtv/mpeg/atscstreamdata.cpp
    a b  
    761761    _cached_cvcts[pid] = cvct;
    762762}
    763763
    764 void ATSCStreamData::DeleteCachedTable(PSIPTable *psip) const
     764bool ATSCStreamData::DeleteCachedTable(PSIPTable *psip) const
    765765{
    766766    if (!psip)
    767         return;
     767        return false;
    768768
    769769    QMutexLocker locker(&_cache_lock);
    770770    if (_cached_ref_cnt[psip] > 0)
    771771    {
    772772        _cached_slated_for_deletion[psip] = 1;
    773         return;
     773        return false;
    774774    }
    775775    else if (TableID::MGT == psip->TableID())
    776776    {
     
    792792    }
    793793    else
    794794    {
    795         MPEGStreamData::DeleteCachedTable(psip);
    796         return;
     795        return MPEGStreamData::DeleteCachedTable(psip);
    797796    }
    798797    psip_refcnt_map_t::iterator it;
    799798    it = _cached_slated_for_deletion.find(psip);
    800799    if (it != _cached_slated_for_deletion.end())
    801800        _cached_slated_for_deletion.erase(it);
     801
     802    return true;
    802803}
    803804
    804805void ATSCStreamData::ReturnCachedTVCTTables(tvct_vec_t &tvcts) const
  • mythtv/libs/libmythtv/mpeg/atscstreamdata.h

    diff -u a/mythtv/libs/libmythtv/mpeg/atscstreamdata.h b/mythtv/libs/libmythtv/mpeg/atscstreamdata.h
    a b  
    120120    void CacheTVCT(uint pid, TerrestrialVirtualChannelTable*);
    121121    void CacheCVCT(uint pid, CableVirtualChannelTable*);
    122122  protected:
    123     virtual void DeleteCachedTable(PSIPTable *psip) const;
     123    virtual bool DeleteCachedTable(PSIPTable *psip) const;
    124124
    125125  private:
    126126    uint                      _GPS_UTC_offset;
  • mythtv/libs/libmythtv/mpeg/dvbstreamdata.cpp

    diff -u a/mythtv/libs/libmythtv/mpeg/dvbstreamdata.cpp b/mythtv/libs/libmythtv/mpeg/dvbstreamdata.cpp
    a b  
    853853    sdts.clear();
    854854}
    855855
    856 void DVBStreamData::DeleteCachedTable(PSIPTable *psip) const
     856bool DVBStreamData::DeleteCachedTable(PSIPTable *psip) const
    857857{
    858858    if (!psip)
    859         return;
     859        return false;
    860860
    861861    uint tid = psip->TableIDExtension();
    862862
     
    864864    if (_cached_ref_cnt[psip] > 0)
    865865    {
    866866        _cached_slated_for_deletion[psip] = 1;
    867         return;
     867        return false;
    868868    }
    869869    else if ((TableID::NIT == psip->TableID()) &&
    870870             _cached_nit[psip->Section()])
     
    880880    }
    881881    else
    882882    {
    883         MPEGStreamData::DeleteCachedTable(psip);
    884         return;
     883        return MPEGStreamData::DeleteCachedTable(psip);
    885884    }
    886885    psip_refcnt_map_t::iterator it;
    887886    it = _cached_slated_for_deletion.find(psip);
    888887    if (it != _cached_slated_for_deletion.end())
    889888        _cached_slated_for_deletion.erase(it);
     889
     890    return true;
    890891}
    891892
    892893void DVBStreamData::CacheNIT(NetworkInformationTable *nit)
  • mythtv/libs/libmythtv/mpeg/dvbstreamdata.h

    diff -u a/mythtv/libs/libmythtv/mpeg/dvbstreamdata.h b/mythtv/libs/libmythtv/mpeg/dvbstreamdata.h
    a b  
    186186    void CacheNIT(NetworkInformationTable*);
    187187    void CacheSDT(ServiceDescriptionTable*);
    188188  protected:
    189     virtual void DeleteCachedTable(PSIPTable *psip) const;
     189    virtual bool DeleteCachedTable(PSIPTable *psip) const;
    190190
    191191  private:
    192192    /// DVB table monitoring
  • mythtv/libs/libmythtv/mpeg/mpegstreamdata.cpp

    diff -u a/mythtv/libs/libmythtv/mpeg/mpegstreamdata.cpp b/mythtv/libs/libmythtv/mpeg/mpegstreamdata.cpp
    a b  
    14051405    _cached_ref_cnt[psip] = _cached_ref_cnt[psip] + 1;
    14061406}
    14071407
    1408 void MPEGStreamData::DeleteCachedTable(PSIPTable *psip) const
     1408bool MPEGStreamData::DeleteCachedTable(PSIPTable *psip) const
    14091409{
    14101410    if (!psip)
    1411         return;
     1411        return false;
    14121412
    14131413    uint tid = psip->TableIDExtension();
    14141414
     
    14161416    if (_cached_ref_cnt[psip] > 0)
    14171417    {
    14181418        _cached_slated_for_deletion[psip] = 1;
    1419         return;
     1419        return false;
    14201420    }
    14211421    else if (TableID::PAT == psip->TableID() &&
    14221422             (_cached_pats[(tid << 8) | psip->Section()] == psip))
     
    14331433    else
    14341434    {
    14351435        _cached_slated_for_deletion[psip] = 2;
    1436         return;
     1436        return false;
    14371437    }
    14381438    psip_refcnt_map_t::iterator it;
    14391439    it = _cached_slated_for_deletion.find(psip);
    14401440    if (it != _cached_slated_for_deletion.end())
    14411441        _cached_slated_for_deletion.erase(it);
     1442
     1443    return true;
    14421444}
    14431445
    14441446void MPEGStreamData::CachePAT(const ProgramAssociationTable *_pat)
  • mythtv/libs/libmythtv/mpeg/mpegstreamdata.h

    diff -u a/mythtv/libs/libmythtv/mpeg/mpegstreamdata.h b/mythtv/libs/libmythtv/mpeg/mpegstreamdata.h
    a b  
    300300
    301301    // Caching
    302302    void IncrementRefCnt(const PSIPTable *psip) const;
    303     virtual void DeleteCachedTable(PSIPTable *psip) const;
     303    virtual bool DeleteCachedTable(PSIPTable *psip) const;
    304304    void CachePAT(const ProgramAssociationTable *pat);
    305305    void CachePMT(const ProgramMapTable *pmt);
    306306
  • mythtv/libs/libmythtv/mpeg/scanstreamdata.cpp

    diff -u a/mythtv/libs/libmythtv/mpeg/scanstreamdata.cpp b/mythtv/libs/libmythtv/mpeg/scanstreamdata.cpp
    a b  
    8181}
    8282
    8383
    84 void ScanStreamData::DeleteCachedTable(PSIPTable *psip) const
     84bool ScanStreamData::DeleteCachedTable(PSIPTable *psip) const
    8585{
    8686    if (!psip)
    87         return;
     87        return false;
    8888
    89     ATSCStreamData::DeleteCachedTable(psip);
    90     if (psip->pesdata())
    91         DVBStreamData::DeleteCachedTable(psip);
     89    if (!ATSCStreamData::DeleteCachedTable(psip))
     90        return DVBStreamData::DeleteCachedTable(psip);
     91    else
     92        return true;
    9293}
  • mythtv/libs/libmythtv/mpeg/scanstreamdata.h

    diff -u a/mythtv/libs/libmythtv/mpeg/scanstreamdata.h b/mythtv/libs/libmythtv/mpeg/scanstreamdata.h
    a b  
    2929    QString GetSIStandard(QString guess = "mpeg") const;
    3030
    3131  private:
    32     virtual void DeleteCachedTable(PSIPTable *psip) const; 
     32    virtual bool DeleteCachedTable(PSIPTable *psip) const; 
    3333};
    3434
    3535#endif // SCANSTREAMDATA_H_