Memory leak when trying to retrieve cover art

Fernando Valente fernando at
Fri Dec 17 23:58:12 CET 2010

Here's my code:

+(NSMutableDictionary *)metadata:(NSString *)mFile{
	NSMutableDictionary *dict = [[[NSMutableDictionary alloc] init]autorelease];
	TagLib::MPEG::File f([mFile UTF8String]);
	TagLib::ID3v2::Tag *t = f.ID3v2Tag(false);
	std::stringstream album;
	album << t->album();
	std::string album2 = album.str();
	if([NSString stringWithUTF8String:album2.c_str()])
		[dict setValue:[NSString stringWithUTF8String:album2.c_str()] forKey:@"album"];
		[dict setValue:@"" forKey:@"album"];
	std::stringstream name;
	name << t->title();
	std::string name2 = name.str();
	if([NSString stringWithUTF8String:name2.c_str()])
		[dict setValue:[NSString stringWithUTF8String:name2.c_str()] forKey:@"name"];
		[dict setValue:@"" forKey:@"name"];
	std::stringstream artist;
	artist << t->artist();
	std::string artist2 = artist.str();
	if([NSString stringWithUTF8String:artist2.c_str()])
		[dict setValue:[NSString stringWithUTF8String:artist2.c_str()] forKey:@"artist"];
		[dict setValue:@"" forKey:@"artist"];
	TagLib::ID3v2::FrameList l = t->frameListMap()["APIC"];
	TagLib::ID3v2::AttachedPictureFrame *pic = static_cast<TagLib::ID3v2::AttachedPictureFrame *> (l.front());
	NSData *mData = [NSData dataWithBytes:pic->picture().data() length:pic->picture().size()];
		[dict setObject:mData forKey:@"cover"];
		[dict setObject:[NSData data] forKey:@"cover"];
	return dict;

On Dec 17, 2010, at 8:35 PM, Lukáš Lalinský wrote:

> On Fri, Dec 17, 2010 at 4:55 PM, Fernando Valente <fernando at> wrote:
>> Hey,
>> I'm using TagLib on a Mac OS X project and I'm having a big problem.
>> Basically, I need to retrieve the cover art from a couple MP3 files and some
>> of them do NOT have a cover art image. The problem is that when I try to get
>> this information, my app crashes. The debugger points to this function:
>> ByteVector AttachedPictureFrame::picture() const
>> {
>>   return d->data;
>> }
>> To be more specific, to the return d->data; line. Anyone knows a solution
>> for that? My life depends on it.
> The code should have no reason to crash, unless you cast a wrong
> pointer (NULL, different type) to AttachedPictureFrame*. I'd need to
> see some of the code to be able to help more.
> Lukas
> _______________________________________________
> taglib-devel mailing list
> taglib-devel at

Best regards,
Fernando Valente

-------------- next part --------------
An HTML attachment was scrubbed...

More information about the taglib-devel mailing list