aboutsummaryrefslogtreecommitdiffstats
path: root/src/db/SimpleDatabasePlugin.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-09-05 20:49:04 +0200
committerMax Kellermann <max@duempel.org>2012-09-05 20:56:20 +0200
commit886255e38afb2e0599080fce11ff9abe4e18dd95 (patch)
treef56f48939f1b43ef29950e572179cd349539abdb /src/db/SimpleDatabasePlugin.cxx
parent0240e75426f483ff558422f99e29708e3f31fdb7 (diff)
downloadmpd-886255e38afb2e0599080fce11ff9abe4e18dd95.tar.gz
mpd-886255e38afb2e0599080fce11ff9abe4e18dd95.tar.xz
mpd-886255e38afb2e0599080fce11ff9abe4e18dd95.zip
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.
Diffstat (limited to 'src/db/SimpleDatabasePlugin.cxx')
-rw-r--r--src/db/SimpleDatabasePlugin.cxx18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/db/SimpleDatabasePlugin.cxx b/src/db/SimpleDatabasePlugin.cxx
index 1e5ffe9bb..d83c1ca73 100644
--- a/src/db/SimpleDatabasePlugin.cxx
+++ b/src/db/SimpleDatabasePlugin.cxx
@@ -261,13 +261,18 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
VisitPlaylist visit_playlist,
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) {
- struct song *song;
- if (visit_song &&
- (song = GetSong(selection.uri, NULL)) != NULL &&
- selection.Match(*song))
- return visit_song(*song, error_r);
+ if (visit_song) {
+ struct song *song =
+ directory_lookup_song(root, selection.uri);
+ if (song != nullptr)
+ return !selection.Match(*song) ||
+ visit_song(*song, error_r);
+ }
g_set_error(error_r, db_quark(), DB_NOT_FOUND,
"No such directory");
@@ -278,7 +283,6 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
!visit_directory(*directory, error_r))
return false;
- ScopeDatabaseLock protect;
return directory->Walk(selection.recursive, selection.filter,
visit_directory, visit_song, visit_playlist,
error_r);