aboutsummaryrefslogtreecommitdiffstats
path: root/Transceiver52M/DriveLoop.cpp
diff options
context:
space:
mode:
authorThomas Tsou <ttsou@vt.edu>2012-03-17 16:47:01 -0400
committerAlexander Chemeris <Alexander.Chemeris@gmail.com>2013-06-24 01:51:02 +0400
commita6ca73ca67b2a66f46be4bafd5ebf397a3c0a2af (patch)
tree5b54e01e15699b685c993744a677e51d79aa68fc /Transceiver52M/DriveLoop.cpp
parent5a37840dfa2a0c02fcb3784afd6969f615b27166 (diff)
multi-arfcn, trx: allocate threads on heap and fix thread release
The underlying pthread of the Thread object isn't created until Thread::start(). If the Thread object is contructed, but not started, then the destructor will fail with a variety of unpredictable errors such as the following or double free() in certain cases. Program received signal SIGSEGV, Segmentation fault. __GI___libc_free (mem=0x3811abed3e946178) at malloc.c:2972 2972 if (chunk_is_mmapped(p)) If the Thread object is stack allocated, but start() isn't called, destructor is guaranteed to run and will fail. The previous approach was to dynamically allocate threads, but not free them, thus avoiding memory errors, but creating memory leaks. To get around this limitation, dynamically allocate Thread objects and initialize with NULL. Then allocate immediately prior to start such that pthread allocation is tied to the Thread object constructor. Deallocation can check that the Thread pointer is valid through NULL or other tracking methods. Signed-off-by: Thomas Tsou <ttsou@vt.edu>
Diffstat (limited to 'Transceiver52M/DriveLoop.cpp')
-rw-r--r--Transceiver52M/DriveLoop.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/Transceiver52M/DriveLoop.cpp b/Transceiver52M/DriveLoop.cpp
index c080c12..7e250f8 100644
--- a/Transceiver52M/DriveLoop.cpp
+++ b/Transceiver52M/DriveLoop.cpp
@@ -29,8 +29,7 @@ DriveLoop::DriveLoop(int wSamplesPerSymbol,
GSM::Time wTransmitLatency,
RadioInterface *wRadioInterface)
{
- mRadioDriveLoopThread = new Thread(32768);
-
+ mRadioDriveLoopThread = NULL;
mSamplesPerSymbol = wSamplesPerSymbol;
mRadioInterface = wRadioInterface;
@@ -70,6 +69,9 @@ DriveLoop::DriveLoop(int wSamplesPerSymbol,
DriveLoop::~DriveLoop()
{
+ if (mRadioDriveLoopThread)
+ delete mRadioDriveLoopThread;
+
delete gsmPulse;
sigProcLibDestroy();
}
@@ -77,6 +79,7 @@ DriveLoop::~DriveLoop()
void DriveLoop::start()
{
mOn = true;
+ mRadioDriveLoopThread = new Thread(32768);
mRadioDriveLoopThread->start((void * (*)(void*))RadioDriveLoopAdapter, (void*) this);
}