Fix memory leak with multi-picture FLAC files.

On my music archive, minidlnad wasn't anywhere near through scanning,
and had already leaked in excess of 10GiB from this.

The basic problem is that song_metadata has one image pointer. When it
sees a picture metadata item, it mallocs some space and copies the
picture to that, then sets the image pointer. That's all well and good,
except FLAC (and some other formats, haven't checked them) allow more
than one picture. So on the second picture, it does the same
thing—except overwriting the previous pointer, thus leaking it.

Simple fix: check if != NULL, ignore picture.

Signed-off-by: Justin Maggard <jmaggard@netgear.com>
This commit is contained in:
Anthony DeRobertis 2015-07-03 00:42:10 -04:00 committed by Justin Maggard
parent a294f624e0
commit 9c5d8c7fd2

View File

@ -75,6 +75,10 @@ _get_flctags(char *filename, struct song_metadata *psong)
break;
#if FLAC_API_VERSION_CURRENT >= 10
case FLAC__METADATA_TYPE_PICTURE:
if (psong->image) {
DPRINTF(E_INFO, L_SCANNER, "Ignoring additional image [%s]\n", filename);
break;
}
psong->image_size = block->data.picture.data_length;
if((psong->image = malloc(psong->image_size)))
memcpy(psong->image, block->data.picture.data, psong->image_size);