rig_cleanup() actually frees the memory allocated by rig_init(), so the
call to free() is a double-free and causes crashes on FreeBSD.
I've also added extra paranoia in around the use of m_rig.
Index: hamlib.cpp
===================================================================
--- hamlib.cpp (revision 1472)
+++ hamlib.cpp (working copy)
@@ -42,9 +42,13 @@
/* Reset debug output. */
rig_set_debug(RIG_DEBUG_VERBOSE);
+
+ m_rig = NULL;
}
Hamlib::~Hamlib() {
+ if(m_rig)
+ close();
}
static int build_list(const struct rig_caps *rig, rig_ptr_t rigList) {
@@ -85,6 +89,11 @@
printf("rig: %s %s (%d)\n", m_rigList[rig_index]->mfg_name,
m_rigList[rig_index]->model_name, m_rigList[rig_index]->rig_model);
+ if(m_rig) {
+ printf("Closing old hamlib instance!\n");
+ close();
+ }
+
/* Initialise, configure and open. */
m_rig = rig_init(m_rigList[rig_index]->rig_model);
/* TODO: Also use baud rate from the screen. */
@@ -101,6 +110,8 @@
}
bool Hamlib::ptt(bool press) {
+ if(!m_rig)
+ return false;
/* TODO(Joel): make ON_DATA and ON configurable. */
ptt_t on = press ? RIG_PTT_ON : RIG_PTT_OFF;
/* TODO(Joel): what should the VFO option be? */
@@ -108,7 +119,9 @@
}
void Hamlib::close(void) {
- rig_close(m_rig);
- rig_cleanup(m_rig);
- free(m_rig);
+ if(m_rig) {
+ rig_close(m_rig);
+ rig_cleanup(m_rig);
+ m_rig = NULL;
+ }
}
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Freetel-codec2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freetel-codec2