aboutsummaryrefslogtreecommitdiffstats
path: root/src/playlist/ExtM3uPlaylistPlugin.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-14 15:47:07 +0100
committerMax Kellermann <max@duempel.org>2014-01-14 22:33:31 +0100
commit1f90e3ce7fc7c12b36db55a104dcbcd7e860bc23 (patch)
treea0ced81b826e69ba09a2abafd6472e3ffc81d3cf /src/playlist/ExtM3uPlaylistPlugin.cxx
parent676d8bb624ef9fb7a8a4983b258d07787efec6b1 (diff)
downloadmpd-1f90e3ce7fc7c12b36db55a104dcbcd7e860bc23.tar.gz
mpd-1f90e3ce7fc7c12b36db55a104dcbcd7e860bc23.tar.xz
mpd-1f90e3ce7fc7c12b36db55a104dcbcd7e860bc23.zip
playlist/extm3u: allocate Tag instance on the stack
Automate the life cycle, making the code safer.
Diffstat (limited to 'src/playlist/ExtM3uPlaylistPlugin.cxx')
-rw-r--r--src/playlist/ExtM3uPlaylistPlugin.cxx19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/playlist/ExtM3uPlaylistPlugin.cxx b/src/playlist/ExtM3uPlaylistPlugin.cxx
index 458222c66..1a975c081 100644
--- a/src/playlist/ExtM3uPlaylistPlugin.cxx
+++ b/src/playlist/ExtM3uPlaylistPlugin.cxx
@@ -67,7 +67,7 @@ extm3u_open_stream(InputStream &is)
*
* @param line the rest of the input line after the colon
*/
-static Tag *
+static Tag
extm3u_parse_tag(const char *line)
{
long duration;
@@ -77,7 +77,7 @@ extm3u_parse_tag(const char *line)
duration = strtol(line, &endptr, 10);
if (endptr[0] != ',')
/* malformed line */
- return NULL;
+ return Tag();
if (duration < 0)
/* 0 means unknown duration */
@@ -87,7 +87,7 @@ extm3u_parse_tag(const char *line)
if (*name == 0 && duration == 0)
/* no information available; don't allocate a tag
object */
- return NULL;
+ return Tag();
TagBuilder tag;
tag.SetTime(duration);
@@ -98,26 +98,23 @@ extm3u_parse_tag(const char *line)
if (*name != 0)
tag.AddItem(TAG_NAME, name);
- return tag.CommitNew();
+ return tag.Commit();
}
DetachedSong *
ExtM3uPlaylist::NextSong()
{
- Tag *tag = NULL;
+ Tag tag;
std::string line;
const char *line_s;
do {
- if (!tis.ReadLine(line)) {
- delete tag;
+ if (!tis.ReadLine(line))
return NULL;
- }
line_s = line.c_str();
if (StringStartsWith(line_s, "#EXTINF:")) {
- delete tag;
tag = extm3u_parse_tag(line_s + 8);
continue;
}
@@ -125,9 +122,7 @@ ExtM3uPlaylist::NextSong()
line_s = strchug_fast(line_s);
} while (line_s[0] == '#' || *line_s == 0);
- DetachedSong *song = new DetachedSong(line_s, std::move(*tag));
- delete tag;
- return song;
+ return new DetachedSong(line_s, std::move(tag));
}
static const char *const extm3u_suffixes[] = {