Ticket #5443: libs_libmythtv_mpegrecorder.cpp-mem-leak.patch

File libs_libmythtv_mpegrecorder.cpp-mem-leak.patch, 1.6 KB (added by Erik Hovland <erik@…>, 16 years ago)

uses auto_ptr to keep from leaking tspacket_fake

  • libs/libmythtv/mpegrecorder.cpp

    tspacket_fake should be deleted whenever the function
    
    From: Erik Hovland <erik@hovland.org>
    
    returns.
    ---
    
     libs/libmythtv/mpegrecorder.cpp |   13 ++++++-------
     1 files changed, 6 insertions(+), 7 deletions(-)
    
    diff --git a/libs/libmythtv/mpegrecorder.cpp b/libs/libmythtv/mpegrecorder.cpp
    index 50d2045..224d554 100644
    a b  
    1515#include <sys/ioctl.h>
    1616#include <sys/time.h>
    1717
     18// C++ headers
    1819#include <algorithm>
     20#include <memory>
    1921using namespace std;
    2022
    2123// avlib headers
    bool MpegRecorder::ProcessTSPacket(const TSPacket &tspacket_real) 
    10341036{
    10351037    const uint pid = tspacket_real.PID();
    10361038
    1037     TSPacket *tspacket_fake = NULL;
     1039    auto_ptr<TSPacket> tspacket_fake(NULL);
    10381040    if ((driver == "hdpvr") && (pid == 0x1001)) // PCRPID for HD-PVR
    10391041    {
    1040         tspacket_fake = tspacket_real.CreateClone();
     1042        tspacket_fake.reset(tspacket_real.CreateClone());
    10411043        uint cc = (_continuity_counter[pid] == 0xFF) ?
    10421044            0 : (_continuity_counter[pid] + 1) & 0xf;
    10431045        tspacket_fake->SetContinuityCounter(cc);
    10441046    }
    10451047
    1046     const TSPacket *tspacket = (tspacket_fake) ?
    1047         tspacket_fake : &tspacket_real;
     1048    const TSPacket *tspacket = (tspacket_fake.get()) ?
     1049        tspacket_fake.get() : &tspacket_real;
    10481050
    10491051    // Check continuity counter
    10501052    if ((pid != 0x1fff) && !CheckCC(pid, tspacket->ContinuityCounter()))
    bool MpegRecorder::ProcessTSPacket(const TSPacket &tspacket_real) 
    10631065
    10641066    BufferedWrite(*tspacket);
    10651067
    1066     if (tspacket_fake)
    1067         delete tspacket_fake;
    1068 
    10691068    return true;
    10701069}
    10711070