libsaria: Delete playlists and renderers when popped

This allows dynamic memory to be freed when we are done using it.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-03-04 10:02:03 -05:00
parent 83897633ce
commit dd5e73a2ba
6 changed files with 26 additions and 1 deletions

View File

@ -18,6 +18,7 @@ struct file
string get_saria_dir();
void make_saria_dir();
bool exists(string);
void remove_file(string);
sid_t lookup_songid(string &);
string open_pipe(string);
void close_pipes();

View File

@ -45,6 +45,7 @@ namespace libsaria
~Playlist();
void set_renderer(PlaylistRenderer *);
void delete_renderer();
void do_load();
void do_save();

View File

@ -48,6 +48,13 @@ bool exists(string path)
return lstat(path.c_str(), &stat) == 0;
}
void remove_file(string filename)
{
string path = get_saria_dir() + "/" + filename;
if (exists(path))
remove(path.c_str());
}
sid_t lookup_songid(string &filepath)
{
struct stat stat;

View File

@ -3,6 +3,8 @@
#include <libsaria/library.h>
#include <libsaria/playlist.h>
#include <stdio.h>
static void load_playlist(void *plist)
{
libsaria::Playlist *playlist = (libsaria::Playlist *)plist;
@ -62,6 +64,11 @@ namespace libsaria
if (filename == "")
return;
if (size() == 0) {
remove_file(filename);
return;
}
task = new IOTask(save_playlist, this);
task->queue();
}

View File

@ -53,6 +53,12 @@ namespace libsaria
renderer = render;
}
void Playlist::delete_renderer()
{
if (renderer)
delete renderer;
}
void Playlist::reload()
{
plist.clear();

View File

@ -45,8 +45,11 @@ namespace libsaria
{
Playlist *plist = playlist_stack.front();
Track *track = plist->next();
if (plist->size() == 0)
if (plist->size() == 0) {
plist->delete_renderer();
delete plist;
playlist_stack.pop_front();
}
return track->get_filepath();
}