[Jack-Devel] Cleanup of clients in libjack2 causes crash
Hello,
I've written a program that can create multiple jack clients and connect
them to jackd.
I'm using a callback passed to jack_on_info_shutdown() to know when a
jack client has exited,
when that happens I deactivate and close the client, and I try to make a
new one every second.
This way I can restart jackd without having to restart my program.
So far so good, until my program started to segfault whenever I closed
jackd.
After some digging I found this code in JackLibGlobals.h:
if (!JackGlobals::fServerRunning && fClientCount > 0) {
// Cleanup remaining clients
jack_error("Jack server was closed but clients are still allocated,
cleanup...");
for (int i = 0; i < CLIENT_NUM; i++) {
JackClient* client = JackGlobals::fClientTable[i];
if (client) {
jack_error("Cleanup client ref = %d", i);
client->Close();
delete client;
JackGlobals::fClientTable[i] = NULL;
}
}
So what happens here is, jackd exits, I deactivate and close a client, I
create a new one with jack_client_open(),
libjack2 then deletes all the other clients, and my program is then left
with several invalid jack_client_t* pointers.
What I suggest here instead, is to just call client->Close() and remove
the client from JackGlobals::fClientTable
(which JackClient::Close() already does btw), and then leave the dealloc
up to the program itself.
Regards,
Bob van Loosen.
1366138591.851_0.ltw:2,a <516D9ED7.2020500 at gmail dot com>