From 51f02679d4b409f7212eaf1dd20135753ade538a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sat, 16 Nov 2024 16:10:00 +0100 Subject: [PATCH] common/playlist: don't allocate duplicated playlist_path If the playlist is loaded directly from a protocol like memory://, the playlist_path represents the entire playlist. In cases where we have a large playlist, this results in the entire playlist being duplicated for each item. For example, if the input size is 300 kB with 10k items, we end up using 3 GB of memory just to store the playlist_path strings. --- common/playlist.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/playlist.c b/common/playlist.c index f4950c1ab2..410d76c3ae 100644 --- a/common/playlist.c +++ b/common/playlist.c @@ -159,9 +159,10 @@ void playlist_append_file(struct playlist *pl, const char *filename) void playlist_populate_playlist_path(struct playlist *pl, const char *path) { + char *playlist_path = talloc_strdup(pl, path); for (int n = 0; n < pl->num_entries; n++) { struct playlist_entry *e = pl->entries[n]; - e->playlist_path = talloc_strdup(e, path); + e->playlist_path = playlist_path; } } @@ -338,6 +339,7 @@ int64_t playlist_transfer_entries_to(struct playlist *pl, int dst_index, e->id = ++pl->id_alloc; pl->entries[e->pl_index] = e; talloc_steal(pl, e); + talloc_steal(pl, e->playlist_path); } playlist_update_indexes(pl, dst_index + count, -1);