fix memleaks (use smartpointers)
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Thu, 12 Jan 2006 15:34:09 +0000 (15:34 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Thu, 12 Jan 2006 15:34:09 +0000 (15:34 +0000)
lib/dvb_ci/dvbci.cpp
lib/dvb_ci/dvbci_appmgr.cpp
lib/dvb_ci/dvbci_resmgr.cpp
lib/dvb_ci/dvbci_session.cpp
lib/dvb_ci/dvbci_session.h

index 80573e8..c3f9148 100644 (file)
@@ -73,6 +73,8 @@ int eDVBCIInterfaces::reset(int slotid)
        if( (slot = getSlot(slotid)) == 0 )
                return -1;
 
        if( (slot = getSlot(slotid)) == 0 )
                return -1;
 
+       eDVBCISession::deleteSessions(slot);
+
        return slot->reset();
 }
 
        return slot->reset();
 }
 
@@ -299,6 +301,7 @@ void eDVBCISlot::data(int what)
                        state = stateRemoved;
                        enableTS(0);
                        printf("ci removed\n");
                        state = stateRemoved;
                        enableTS(0);
                        printf("ci removed\n");
+                       eDVBCISession::deleteSessions(this);
                        notifier->setRequested(eSocketNotifier::Read);
                        //HACK
                        eDVBCI_UI::getInstance()->setState(0,0);
                        notifier->setRequested(eSocketNotifier::Read);
                        //HACK
                        eDVBCI_UI::getInstance()->setState(0,0);
index f5231fc..28e0659 100644 (file)
@@ -92,5 +92,6 @@ int eDVBCIApplicationManagerSession::startMMI()
        printf("in appmanager -> startmmi()\n");
        const unsigned char tag[3]={0x9F, 0x80, 0x22};  // Tenter_menu
        sendAPDU(tag);
        printf("in appmanager -> startmmi()\n");
        const unsigned char tag[3]={0x9F, 0x80, 0x22};  // Tenter_menu
        sendAPDU(tag);
+       return 0;
 }
 
 }
 
index 7f716d6..69ff611 100644 (file)
@@ -83,6 +83,7 @@ int eDVBCIResourceManagerSession::doAction()
        case stateFinal:
                printf("stateFinal und action! kann doch garnicht sein ;)\n");
        default:
        case stateFinal:
                printf("stateFinal und action! kann doch garnicht sein ;)\n");
        default:
-               return 0;
+               break;
        }
        }
+       return 0;
 }
 }
index 9b5cd87..7156811 100644 (file)
@@ -7,7 +7,9 @@
 #include <lib/dvb_ci/dvbci_datetimemgr.h>
 #include <lib/dvb_ci/dvbci_mmi.h>
 
 #include <lib/dvb_ci/dvbci_datetimemgr.h>
 #include <lib/dvb_ci/dvbci_mmi.h>
 
-eDVBCISession *eDVBCISession::sessions[SLMS];
+DEFINE_REF(eDVBCISession);
+
+ePtr<eDVBCISession> eDVBCISession::sessions[SLMS];
 
 int eDVBCISession::buildLengthField(unsigned char *pkt, int len)
 {
 
 int eDVBCISession::buildLengthField(unsigned char *pkt, int len)
 {
@@ -108,9 +110,19 @@ void eDVBCISession::recvCloseSessionRequest(const unsigned char *data)
        printf("close Session Request\n");
 }
 
        printf("close Session Request\n");
 }
 
-eDVBCISession *eDVBCISession::createSession(eDVBCISlot *slot, const unsigned char *resource_identifier, unsigned char &status)
+void eDVBCISession::deleteSessions(const eDVBCISlot *slot)
+{
+       ePtr<eDVBCISession> ptr;
+       for (unsigned short session_nb=0; session_nb < SLMS; ++session_nb)
+       {
+               ptr = sessions[session_nb];
+               if (ptr && ptr->slot == slot)
+                       sessions[session_nb]=0;
+       }
+}
+
+void eDVBCISession::createSession(eDVBCISlot *slot, const unsigned char *resource_identifier, unsigned char &status, ePtr<eDVBCISession> &session)
 {
 {
-       eDVBCISession *session;
        unsigned long tag;
        unsigned short session_nb;
 
        unsigned long tag;
        unsigned short session_nb;
 
@@ -120,7 +132,7 @@ eDVBCISession *eDVBCISession::createSession(eDVBCISlot *slot, const unsigned cha
        if (session_nb == SLMS)
        {
                status=0xF3;
        if (session_nb == SLMS)
        {
                status=0xF3;
-               return 0;
+               return;
        }
 
        tag = resource_identifier[0] << 24;
        }
 
        tag = resource_identifier[0] << 24;
@@ -133,7 +145,6 @@ eDVBCISession *eDVBCISession::createSession(eDVBCISlot *slot, const unsigned cha
        case 0x00010041:
                session=new eDVBCIResourceManagerSession;
                printf("RESOURCE MANAGER\n");
        case 0x00010041:
                session=new eDVBCIResourceManagerSession;
                printf("RESOURCE MANAGER\n");
-               printf("session: %p\n",session);
                break;
        case 0x00020041:
                session=new eDVBCIApplicationManagerSession(slot);
                break;
        case 0x00020041:
                session=new eDVBCIApplicationManagerSession(slot);
@@ -165,9 +176,10 @@ eDVBCISession *eDVBCISession::createSession(eDVBCISlot *slot, const unsigned cha
        if (!session)
        {
                printf("unknown session.. expect crash\n");
        if (!session)
        {
                printf("unknown session.. expect crash\n");
-               return 0;
+               return;
        }
        }
-       printf("new session_nb: %d\n", session_nb);
+
+       printf("new session nb %d %p\n", session_nb, &(*session));
        session->session_nb = session_nb;
 
        if (session)
        session->session_nb = session_nb;
 
        if (session)
@@ -177,8 +189,6 @@ eDVBCISession *eDVBCISession::createSession(eDVBCISlot *slot, const unsigned cha
                status = 0;
        }
        session->state = stateInCreation;
                status = 0;
        }
        session->state = stateInCreation;
-
-       return session;
 }
 
 void eDVBCISession::handleClose()
 }
 
 void eDVBCISession::handleClose()
@@ -197,7 +207,6 @@ int eDVBCISession::pollAll()
                        if (sessions[session_nb-1]->state == stateInDeletion)
                        {
                                sessions[session_nb-1]->handleClose();
                        if (sessions[session_nb-1]->state == stateInDeletion)
                        {
                                sessions[session_nb-1]->handleClose();
-                               delete sessions[session_nb-1];
                                sessions[session_nb-1]=0;
                                r=1;
                        } else
                                sessions[session_nb-1]=0;
                                r=1;
                        } else
@@ -216,22 +225,20 @@ void eDVBCISession::receiveData(eDVBCISlot *slot, const unsigned char *ptr, size
        int llen, hlen;
 
        printf("slot: %p\n",slot);
        int llen, hlen;
 
        printf("slot: %p\n",slot);
-       
-       int i;
-       
-       for(i=0;i<len;i++)
+
+       for(unsigned int i=0;i<len;i++)
                printf("%02x ",ptr[i]);
        printf("\n");
        
        llen = parseLengthField(pkt, hlen);
        pkt += llen;
        
                printf("%02x ",ptr[i]);
        printf("\n");
        
        llen = parseLengthField(pkt, hlen);
        pkt += llen;
        
-       eDVBCISession *session = NULL;
+       ePtr<eDVBCISession> session;
        
        if(tag == 0x91)
        {
                unsigned char status;
        
        if(tag == 0x91)
        {
                unsigned char status;
-               session = createSession(slot, pkt, status);
+               createSession(slot, pkt, status, session);
                sendOpenSessionResponse(slot, status, pkt, session?session->session_nb:0);
                
                if (session)
                sendOpenSessionResponse(slot, status, pkt, session?session->session_nb:0);
                
                if (session)
@@ -312,5 +319,6 @@ void eDVBCISession::receiveData(eDVBCISlot *slot, const unsigned char *ptr, size
 
 eDVBCISession::~eDVBCISession()
 {
 
 eDVBCISession::~eDVBCISession()
 {
+       printf("destroy %p\n", this);
 }
 
 }
 
index 1705d76..cf69ca9 100644 (file)
@@ -2,14 +2,17 @@
 #define __dvbci_dvbci_tc_h
 
 #include <lib/base/ebase.h>
 #define __dvbci_dvbci_tc_h
 
 #include <lib/base/ebase.h>
+#include <lib/base/object.h>
 #include <lib/dvb_ci/dvbci.h>
 
 #define SLMS   256
 
 class eDVBCISession
 {
 #include <lib/dvb_ci/dvbci.h>
 
 #define SLMS   256
 
 class eDVBCISession
 {
-       static eDVBCISession *sessions[SLMS];
-       static eDVBCISession *eDVBCISession::createSession(eDVBCISlot *slot, const unsigned char *resource_identifier, unsigned char &status);
+       DECLARE_REF(eDVBCISession);
+       static ePtr<eDVBCISession> sessions[SLMS];
+       static void eDVBCISession::deleteSessions(const eDVBCISlot *slot);
+       static void eDVBCISession::createSession(eDVBCISlot *slot, const unsigned char *resource_identifier, unsigned char &status, ePtr<eDVBCISession> &ptr);
        static void eDVBCISession::sendSPDU(eDVBCISlot *slot, unsigned char tag,const void *data, int len, unsigned short session_nb, const void *apdu=0,int alen=0);
        static void sendOpenSessionResponse(eDVBCISlot *slot,unsigned char session_status, const unsigned char *resource_identifier,unsigned short session_nb);
        void recvCreateSessionResponse(const unsigned char *data);
        static void eDVBCISession::sendSPDU(eDVBCISlot *slot, unsigned char tag,const void *data, int len, unsigned short session_nb, const void *apdu=0,int alen=0);
        static void sendOpenSessionResponse(eDVBCISlot *slot,unsigned char session_status, const unsigned char *resource_identifier,unsigned short session_nb);
        void recvCreateSessionResponse(const unsigned char *data);