Memory leak when trying to retrieve cover art

Fernando Valente fernando at fvalente.org
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"];
	else
		[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"];
	else
		[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"];
	else
		[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()];
	if(mData)
		[dict setObject:mData forKey:@"cover"];
	else
		[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 fvalente.org> 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 kde.org
> https://mail.kde.org/mailman/listinfo/taglib-devel

Best regards,
Fernando Valente
http://www.chiarosoft.com/
http://www.fvalente.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.kde.org/pipermail/taglib-devel/attachments/20101217/7d7e00ba/attachment-0001.htm 


More information about the taglib-devel mailing list