directory_save: duplicate the playlist name

The function playlist_metadata_load() will overwrite the input buffer
before using the "name" parameter; since "name" points to the same
buffer, we'll get a corrupted string.
This commit is contained in:
Max Kellermann
2010-07-25 12:01:29 +02:00
parent 31ab0b3df1
commit 7820ebb82e

View File

@@ -172,11 +172,18 @@ directory_load(FILE *fp, struct directory *directory,
songvec_add(&directory->songs, song); songvec_add(&directory->songs, song);
} else if (g_str_has_prefix(line, PLAYLIST_META_BEGIN)) { } else if (g_str_has_prefix(line, PLAYLIST_META_BEGIN)) {
const char *name = line + sizeof(PLAYLIST_META_BEGIN) - 1; /* duplicate the name, because
playlist_metadata_load() will overwrite the
buffer */
char *name = g_strdup(line + sizeof(PLAYLIST_META_BEGIN) - 1);
if (!playlist_metadata_load(fp, &directory->playlists, if (!playlist_metadata_load(fp, &directory->playlists,
name, buffer, error)) name, buffer, error)) {
g_free(name);
return false; return false;
}
g_free(name);
} else { } else {
g_set_error(error, directory_quark(), 0, g_set_error(error, directory_quark(), 0,
"Malformed line: %s", line); "Malformed line: %s", line);