From 07b26dd89ca2c69ac60886c03d67e5272a33ec22 Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
Date: Wed, 15 Sep 2010 17:54:58 -0400
Subject: [PATCH] [#4068] Make sure to not delete a NULL pointer in IAX voip
 link destructor

---
 sflphone-common/src/iax/iaxvoiplink.cpp | 78 ++++++++++++++++---------
 sflphone-common/src/managerimpl.cpp     |  2 +-
 2 files changed, 50 insertions(+), 30 deletions(-)

diff --git a/sflphone-common/src/iax/iaxvoiplink.cpp b/sflphone-common/src/iax/iaxvoiplink.cpp
index a9d4f117ea..a997aa4f19 100644
--- a/sflphone-common/src/iax/iaxvoiplink.cpp
+++ b/sflphone-common/src/iax/iaxvoiplink.cpp
@@ -51,20 +51,26 @@
 #define CHK_VALID_CALL   if (call == NULL) { _debug("IAX: Call doesn't exists"); \
 	return false; }
 
-IAXVoIPLink::IAXVoIPLink (const AccountID& accountID)
-        : VoIPLink (accountID)
+IAXVoIPLink::IAXVoIPLink (const AccountID& accountID) : VoIPLink (accountID)
+        , _evThread (NULL)
+        , _regSession (NULL)
+        , _nextRefreshStamp (0)
+        , audiolayer (NULL)
+        , micData (NULL)
+        , micDataConverted (NULL)
+        , micDataEncoded (NULL)
+        , spkrDataDecoded (NULL)
+        , spkrDataConverted (NULL)
+        , converter (NULL)
+        , converterSamplingRate (NULL)
+        , urlhook (NULL)
+        , countTime (0)
 {
-    // _debug("IAXVoIPLink::IAXVoIPLink : creating eventhread  ");
     _evThread = new EventThread (this);
-    _regSession = NULL;
-    _nextRefreshStamp = 0;
-    countTime = 0;
 
     // to get random number for RANDOM_PORT
     srand (time (NULL));
 
-    audiolayer = NULL;
-
     converter = new SamplerateConverter();
 
     int nbSamplesMax = (int) (converter->getFrequence() * converter->getFramesize() / 1000);
@@ -82,26 +88,46 @@ IAXVoIPLink::IAXVoIPLink (const AccountID& accountID)
 
 IAXVoIPLink::~IAXVoIPLink()
 {
-    delete _evThread;
-    _evThread = NULL;
+    if (_evThread) {
+        delete _evThread;
+        _evThread = NULL;
+    }
+
     _regSession = NULL; // shall not delete it
     terminate();
 
     audiolayer = NULL;
 
-    delete converter;
+    if (converter) {
+        delete converter;
+        converter = NULL;
+    }
 
-    delete [] micData;
-    micData = NULL;
-    delete [] micDataConverted;
-    micDataConverted = NULL;
-    delete [] micDataEncoded;
-    micDataEncoded = NULL;
+    if (micData) {
+        delete [] micData;
+        micData = NULL;
+    }
+
+    if (micDataConverted) {
+        delete [] micDataConverted;
+        micDataConverted = NULL;
+    }
+
+    if (micDataEncoded) {
+        delete [] micDataEncoded;
+        micDataEncoded = NULL;
+    }
+
+    if (spkrDataDecoded) {
+        delete [] spkrDataDecoded;
+        spkrDataDecoded = NULL;
+    }
+
+    if (spkrDataConverted) {
+        delete [] spkrDataConverted;
+        spkrDataConverted = NULL;
+    }
 
-    delete [] spkrDataDecoded;
-    spkrDataDecoded = NULL;
-    delete [] spkrDataConverted;
-    spkrDataConverted = NULL;
 }
 
 bool
@@ -254,12 +280,6 @@ IAXVoIPLink::getEvent()
 
     sendAudioFromMic();
 
-    if (call) {
-        call->recAudio.recData (spkrDataDecoded, micData, nbSampleForRec_, nbSampleForRec_);
-
-        // Do the doodle-moodle to send audio from the microphone to the IAX channel.
-    }
-
     // Do the doodle-moodle to send audio from the microphone to the IAX channel.
     // sendAudioFromMic();
 
@@ -537,7 +557,7 @@ IAXVoIPLink::answer (const CallID& id)
 bool
 IAXVoIPLink::hangup (const CallID& id)
 {
-    _debug ("IAXVoIPLink::hangup() : function called once hangup ");
+    _debug ("IAXVoIPLink: Hangup");
     IAXCall* call = getIAXCall (id);
     std::string reason = "Dumped Call";
     CHK_VALID_CALL;
@@ -565,7 +585,7 @@ IAXVoIPLink::hangup (const CallID& id)
 bool
 IAXVoIPLink::peerHungup (const CallID& id)
 {
-    _debug ("IAXVoIPLink::peerHangup() : function called once hangup ");
+    _debug ("IAXVoIPLink: Peer hung up");
     IAXCall* call = getIAXCall (id);
     std::string reason = "Dumped Call";
     CHK_VALID_CALL;
diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp
index a9ae013bd5..8520f647ef 100644
--- a/sflphone-common/src/managerimpl.cpp
+++ b/sflphone-common/src/managerimpl.cpp
@@ -3821,7 +3821,7 @@ void ManagerImpl::unloadAccountMap ()
 
     while (iter != _accountMap.end()) {
 
-        _debug ("Unloading account %s", iter->first.c_str());
+        _debug ("Manager: Unloading account %s", iter->first.c_str());
 
         delete iter->second;
         iter->second = NULL;
-- 
GitLab