Fix file handle leak in vgmstream decoder.

CQTexperiment
Chris Moeller 2016-06-30 15:40:43 -07:00
parent 27e5402d88
commit ed33e37214
1 changed files with 11 additions and 6 deletions

View File

@ -110,15 +110,13 @@ VGMSTREAM *init_vgmstream_from_cogfile(const char *path) {
VGMSTREAM *vgm;
sf = cogsf_create_from_path(path);
if (!sf) return NULL;
vgm = init_vgmstream_from_STREAMFILE(sf);
if (!vgm) goto err1;
if (sf) {
vgm = init_vgmstream_from_STREAMFILE(sf);
cogsf_close((COGSTREAMFILE *)sf);
}
return vgm;
err1:
cogsf_close((COGSTREAMFILE *)sf);
return NULL;
}
@implementation VGMDecoder
@ -195,6 +193,13 @@ err1:
- (long)seek:(long)frame
{
// Constrain the seek offset to within the loop, if any
if(stream->loop_flag && (stream->loop_end_sample - stream->loop_start_sample) && frame >= stream->loop_end_sample) {
frame -= stream->loop_start_sample;
frame %= (stream->loop_end_sample - stream->loop_start_sample);
frame += stream->loop_start_sample;
}
if (frame < framesRead) {
reset_vgmstream( stream );
framesRead = 0;