Skip to content
Commit dab0a7a6 authored by Frank Schaefer's avatar Frank Schaefer
Browse files

AsyncMusicBrainzLookup: fix a crash and a memory leak

From the documentation of QThread::~QThread():
"... Note that deleting a QThread object will not stop the execution of the
 thread it manages. Deleting a running QThread (i.e. isFinished() returns false)
 will probably result in a program crash.
 Wait for the finished() signal before deleting the QThread."

The destructor of class AsyncMusicBrainzLookup currently just deletes the lookup
thread object and does _not_ wait for the running thread to finish.
If it is called while the lookup thread is still running, a crash occurs.

In addition to that, we are leaking the memory of a previously instanciated
lookup thread object if the lookup() method is called multiple times.

To maintain the current behavior of the destructor (non-blocking) and the
lookup() method (always start a new lookup without canceling pending lookups),
solve both issues by making the lookup thread object self-destructive.
As part of the solution the lookup thread is modifed to deliver the lookup results
directly with the "lookupFinished" signal. This has two benefits:
1.) the queued signal-slot connection avoids thread synchronization/locking issues
2.) some class members become obsolete
parent 53d598a9
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment