Skip to content

AsyncMusicBrainzLookup: fix a crash and a memory leak

Frank Schaefer requested to merge fschaefer/libkcddb:master into master

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.

BUG: 336678

Edited by Frank Schaefer

Merge request reports