Fix resource leak with VGMStream container parser, and serialize metadata caching from there as well

This commit is contained in:
Christopher Snowhill 2019-12-19 17:12:09 -08:00
parent 072c4346cf
commit 37b75bf6e7

View file

@ -36,23 +36,46 @@
return [NSMutableArray arrayWithObject:url]; return [NSMutableArray arrayWithObject:url];
} }
VGMSTREAM * stream = init_vgmstream_from_cogfile([[[url absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] UTF8String], 0); NSString * path = [[url absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
VGMSTREAM * stream = init_vgmstream_from_cogfile([path UTF8String], 0);
if (!stream) if (!stream)
{ {
ALog(@"Open failed for file: %@", [url absoluteString]); ALog(@"Open failed for file: %@", [url absoluteString]);
return NO; return [NSArray array];
} }
VGMInfoCache * sharedMyCache = [VGMInfoCache sharedCache];
NSMutableArray *tracks = [NSMutableArray array]; NSMutableArray *tracks = [NSMutableArray array];
NSURL * trackurl;
int i; int i;
int subsongs = stream->num_streams; int subsongs = stream->num_streams;
if (subsongs == 0) if (subsongs == 0)
subsongs = 1; subsongs = 1;
for (i = 1; i <= subsongs; ++i) {
[tracks addObject:[NSURL URLWithString:[[url absoluteString] stringByAppendingFormat:@"#%i", i]]]; {
trackurl = [NSURL URLWithString:[[url absoluteString] stringByAppendingString:@"#1"]];
[sharedMyCache stuffURL:trackurl stream:stream];
[tracks addObject:trackurl];
} }
for (i = 2; i <= subsongs; ++i) {
close_vgmstream(stream);
stream = init_vgmstream_from_cogfile([path UTF8String], i);
if (!stream)
return [NSArray array];
trackurl = [NSURL URLWithString:[[url absoluteString] stringByAppendingFormat:@"#%i", i]];
[sharedMyCache stuffURL:trackurl stream:stream];
[tracks addObject:trackurl];
}
close_vgmstream(stream);
return tracks; return tracks;
} }