Ticket #5136: libs_libmythtv_mpeg_mpegstreamdata.cpp-avoid-use-after-free.patch

File libs_libmythtv_mpeg_mpegstreamdata.cpp-avoid-use-after-free.patch, 1.6 KB (added by Erik Hovland <erik@…>, 12 years ago)

defer deleting psip until after it is used for the last time

  • libs/libmythtv/mpeg/mpegstreamdata.cpp

    Make sure that psip is deleted after we are done with it.
    
    From: Erik Hovland <erik@hovland.org>
    
    
    ---
    
     libs/libmythtv/mpeg/mpegstreamdata.cpp |   11 +++++++++--
     1 files changed, 9 insertions(+), 2 deletions(-)
    
    diff --git a/libs/libmythtv/mpeg/mpegstreamdata.cpp b/libs/libmythtv/mpeg/mpegstreamdata.cpp
    index ad07f4f..19e5dea 100644
    a b void MPEGStreamData::DeleteCachedTable(PSIPTable *psip) const 
    13881388        return;
    13891389
    13901390    uint tid = psip->TableIDExtension();
     1391    bool delete_psip = false;
    13911392
    13921393    QMutexLocker locker(&_cache_lock);
    13931394    if (_cached_ref_cnt[psip] > 0)
    void MPEGStreamData::DeleteCachedTable(PSIPTable *psip) const 
    13991400             (_cached_pats[(tid << 8) | psip->Section()] == psip))
    14001401    {
    14011402        _cached_pats[(tid << 8) | psip->Section()] = NULL;
    1402         delete psip;
     1403        delete_psip = true;
    14031404    }
    14041405    else if ((TableID::PMT == psip->TableID()) &&
    14051406             (_cached_pmts[(tid << 8) | psip->Section()] == psip))
    14061407    {
    14071408        _cached_pmts[(tid << 8) | psip->Section()] = NULL;
    1408         delete psip;
     1409        delete_psip = true;
    14091410    }
    14101411    else
    14111412    {
    void MPEGStreamData::DeleteCachedTable(PSIPTable *psip) const 
    14161417    it = _cached_slated_for_deletion.find(psip);
    14171418    if (it != _cached_slated_for_deletion.end())
    14181419        _cached_slated_for_deletion.erase(it);
     1420
     1421    if (delete_psip)
     1422    {
     1423        delete(psip);
     1424        psip = NULL;
     1425    }
    14191426}
    14201427
    14211428void MPEGStreamData::CachePAT(const ProgramAssociationTable *_pat)