]> git.vomp.tv Git - vompclient-marten.git/commitdiff
A memory leak fix
authorChris Tallon <chris@vomp.tv>
Mon, 15 Aug 2005 01:02:27 +0000 (01:02 +0000)
committerChris Tallon <chris@vomp.tv>
Mon, 15 Aug 2005 01:02:27 +0000 (01:02 +0000)
afeed.h
afeedr.h
player.h
playerradio.h
playervideo.cc
playervideo.h
thread.cc
thread.h
vconnect.h
vfeed.h

diff --git a/afeed.h b/afeed.h
index b858e965c6bbdb93b4ddf2f608c9a0ad323ce952..ba465c9125b53499099e14bc40e1c976d7f82af3 100644 (file)
--- a/afeed.h
+++ b/afeed.h
@@ -44,6 +44,7 @@ class AFeed : public Thread
 
   private:
     void threadMethod();
+    void threadPostStopCleanup() {};
     int audioEnabled;
     int fd;
     Callback& cb;
index eb94db2eef603d8739e7d0d96da103ea52a1e3f9..939d9196706acce6ab5f007191e9f98186da943f 100644 (file)
--- a/afeedr.h
+++ b/afeedr.h
@@ -42,6 +42,8 @@ class AFeedR : public Thread
 
   private:
     void threadMethod();
+    void threadPostStopCleanup() {};
+
     int fd;
     Callback& cb;
     Stream& stream;
index 65bf70f45e93fd8c01f6f62dcdbbbb2a8bd57095..87711ce28036ad2dd64708b89b1899d4ec174e24 100644 (file)
--- a/player.h
+++ b/player.h
@@ -49,6 +49,7 @@ class Player : public Thread, public Callback
 
     virtual void call()=0; // for callback interface
     virtual void threadMethod()=0; // for thread interface
+    virtual void threadPostStopCleanup()=0;
 
   protected:
     int initted;
index 82a9ce0eb4b04f35df4edf6a6c4c16d21a7a6e5c..dab5d3ea3a944910941e35982d159e041b5bafe2 100644 (file)
@@ -54,6 +54,7 @@ class PlayerRadio : public Player
     void setLength(ULLONG length);
 
     void threadMethod();
+    void threadPostStopCleanup() {};
 
     void skipForward(int) {};
     void skipBackward(int) {};
index 8b4fe5e11bb981814177088becf2059e4247d315..4ad52fee0b5ac46aafcc5481c0a7c164a222c527 100644 (file)
@@ -33,6 +33,7 @@ PlayerVideo::PlayerVideo(MessageQueue* messageQueue, UCHAR tIsRecording)
   feedMode = MODE_NORMAL;
   isRecording = tIsRecording;
   lastRescan = 0;
+  threadBuffer = NULL;
 }
 
 PlayerVideo::~PlayerVideo()
@@ -491,7 +492,6 @@ void PlayerVideo::call()
 
 void PlayerVideo::threadMethod()
 {
-  UCHAR* buf;
   UINT thisRead;
   UINT writeLength;
   UINT thisWrite;
@@ -542,12 +542,12 @@ void PlayerVideo::threadMethod()
         askFor = blockSize; // normal
     }
 
-    buf = vdr->getBlock(feedPosition, askFor, &thisRead);
-    if (!buf) break;
+    threadBuffer = vdr->getBlock(feedPosition, askFor, &thisRead);
+    if (!threadBuffer) break;
 
     if (startup)
     {
-      int a_stream = demuxer.scan(buf, thisRead);
+      int a_stream = demuxer.scan(threadBuffer, thisRead);
       demuxer.setAudioStream(a_stream);
       Log::getInstance()->log("Player", Log::DEBUG, "Startup Audio stream chosen %x", a_stream);
       startup = 0;
@@ -575,7 +575,7 @@ void PlayerVideo::threadMethod()
 
     while(writeLength < thisRead)
     {
-      thisWrite = demuxer.put(buf + writeLength, thisRead - writeLength);
+      thisWrite = demuxer.put(threadBuffer + writeLength, thisRead - writeLength);
       writeLength += thisWrite;
 
       if (!thisWrite)
@@ -589,7 +589,8 @@ void PlayerVideo::threadMethod()
       threadCheckExit();
     }
 
-    free(buf);
+    free(threadBuffer);
+    threadBuffer = NULL;
 
   }
 
@@ -603,3 +604,14 @@ void PlayerVideo::threadMethod()
 
 
 }
+
+void PlayerVideo::threadPostStopCleanup()
+{
+  Log::getInstance()->log("Player", Log::DEBUG, "Post stop cleanup 1");
+  if (threadBuffer)
+  {
+    Log::getInstance()->log("Player", Log::DEBUG, "Post stop cleanup 2");
+    free(threadBuffer);
+    threadBuffer = NULL;
+  }
+}
index eb5884917f7bc14b559dbcd2109f52b68bc3ed1c..96ad61c06b6a6abbe9b64685c9b833620abb80e1 100644 (file)
@@ -60,6 +60,7 @@ class PlayerVideo : public Player
     void setLength(ULLONG length);
 
     void threadMethod();
+    void threadPostStopCleanup();
 
   private:
     MessageQueue* commandMessageQueue;
@@ -76,6 +77,7 @@ class PlayerVideo : public Player
     const static UCHAR MODE_BACKWARDS = 2;
     const static UINT blockSize = 100000;
     const static UINT startupBlockSize = 250000;
+    UCHAR* threadBuffer;
 
     UCHAR playing;    // As in not stopped, (playing && paused) can == TRUE
     UCHAR paused;     // Must be in playing state as well
index 75b4281dcb15605865ce91b2cd223cff25a495cb..b6cc8ffa1544c7c2a18dd4bd924cca513b6a0fae 100644 (file)
--- a/thread.cc
+++ b/thread.cc
@@ -53,6 +53,7 @@ void Thread::threadStop()
   // Signal thread here in case it's waiting
   threadSignal();
   pthread_join(pthread, NULL);
+  this->threadPostStopCleanup();
 }
 
 void Thread::threadCancel()
@@ -60,6 +61,7 @@ void Thread::threadCancel()
   threadActive = 0;
   pthread_cancel(pthread);
   pthread_join(pthread, NULL);
+  this->threadPostStopCleanup();
 }
 
 void Thread::threadCheckExit()
index d57375a8ea044a86023d5e1b355ad6f0f7f29d11..111ede4de2bb8a0a1c4c953604c059968520fe54 100644 (file)
--- a/thread.h
+++ b/thread.h
 #include <pthread.h>
 #include <signal.h>
 
+#include <stdio.h> // temp
+
 class Thread
 {
   protected:
     // Override this method in derived classes
     virtual void threadMethod()=0;
+    virtual void threadPostStopCleanup()=0;
 
     // Methods to use from outside the thread
     int threadStart();    // start the thread. threadMethod() will be called in derived class
index 545f5a9cdeb0962ffeb6c37c2c5989d77895cd6c..b9f086e86f72a3702fba12864fb2c724413e3d7a 100644 (file)
@@ -48,6 +48,7 @@ class VConnect : public VInfo, public Thread
 
   private:
     void threadMethod();
+    void threadPostStopCleanup() {};
     void clearServerIPs();
 
     UCHAR irun;
diff --git a/vfeed.h b/vfeed.h
index 2e7019b587b46d76a07e5680cc6758763c675e6f..51cd666921b2b2a047188d8e82c5c0e58e2ba40a 100644 (file)
--- a/vfeed.h
+++ b/vfeed.h
@@ -42,6 +42,7 @@ class VFeed : public Thread
 
   private:
     void threadMethod();
+    void threadPostStopCleanup() {};
     int fd;
     Callback& cb;
     struct timespec delayTime;