db/SimpleDatabasePlugin: fix memory leak in Visit()
When visiting a song, GetSong() was called, but this object was never returned by calling ReturnSong(). This patch locks the database only once in Visit() and passes the original song object to the visitor, avoiding the copy.
This commit is contained in:
parent
0240e75426
commit
886255e38a
@ -261,13 +261,18 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
|
|||||||
VisitPlaylist visit_playlist,
|
VisitPlaylist visit_playlist,
|
||||||
GError **error_r) const
|
GError **error_r) const
|
||||||
{
|
{
|
||||||
const struct directory *directory = LookupDirectory(selection.uri);
|
ScopeDatabaseLock protect;
|
||||||
|
|
||||||
|
const struct directory *directory =
|
||||||
|
directory_lookup_directory(root, selection.uri);
|
||||||
if (directory == NULL) {
|
if (directory == NULL) {
|
||||||
struct song *song;
|
if (visit_song) {
|
||||||
if (visit_song &&
|
struct song *song =
|
||||||
(song = GetSong(selection.uri, NULL)) != NULL &&
|
directory_lookup_song(root, selection.uri);
|
||||||
selection.Match(*song))
|
if (song != nullptr)
|
||||||
return visit_song(*song, error_r);
|
return !selection.Match(*song) ||
|
||||||
|
visit_song(*song, error_r);
|
||||||
|
}
|
||||||
|
|
||||||
g_set_error(error_r, db_quark(), DB_NOT_FOUND,
|
g_set_error(error_r, db_quark(), DB_NOT_FOUND,
|
||||||
"No such directory");
|
"No such directory");
|
||||||
@ -278,7 +283,6 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
|
|||||||
!visit_directory(*directory, error_r))
|
!visit_directory(*directory, error_r))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ScopeDatabaseLock protect;
|
|
||||||
return directory->Walk(selection.recursive, selection.filter,
|
return directory->Walk(selection.recursive, selection.filter,
|
||||||
visit_directory, visit_song, visit_playlist,
|
visit_directory, visit_song, visit_playlist,
|
||||||
error_r);
|
error_r);
|
||||||
|
Loading…
Reference in New Issue
Block a user