FS#7954: Free resources when speed testing a folder. Also simplify the error handling code a little.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15934 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Magnus Holmgren 2007-12-15 13:54:58 +00:00
parent 2ab4636e95
commit c21f59090e

View file

@ -514,7 +514,7 @@ static enum plugin_status test_track(char* filename)
{ {
size_t n; size_t n;
int fd; int fd;
enum plugin_status res = PLUGIN_OK; enum plugin_status res = PLUGIN_ERROR;
unsigned long starttick; unsigned long starttick;
unsigned long ticks; unsigned long ticks;
unsigned long speed; unsigned long speed;
@ -538,7 +538,7 @@ static enum plugin_status test_track(char* filename)
if (fd < 0) if (fd < 0)
{ {
log_text("Cannot open file",true); log_text("Cannot open file",true);
return PLUGIN_ERROR; goto exit;
} }
track.filesize = rb->filesize(fd); track.filesize = rb->filesize(fd);
@ -549,13 +549,13 @@ static enum plugin_status test_track(char* filename)
if (!rb->get_metadata(&(track.id3), fd, filename)) if (!rb->get_metadata(&(track.id3), fd, filename))
{ {
log_text("Cannot read metadata",true); log_text("Cannot read metadata",true);
return PLUGIN_ERROR; goto exit;
} }
if (track.filesize > audiosize) if (track.filesize > audiosize)
{ {
log_text("File too large",true); log_text("File too large",true);
return PLUGIN_ERROR; goto exit;
} }
n = rb->read(fd, audiobuf, track.filesize); n = rb->read(fd, audiobuf, track.filesize);
@ -563,7 +563,6 @@ static enum plugin_status test_track(char* filename)
if (n != track.filesize) if (n != track.filesize)
{ {
log_text("Read failed.",true); log_text("Read failed.",true);
res = PLUGIN_ERROR;
goto exit; goto exit;
} }
@ -606,11 +605,8 @@ static enum plugin_status test_track(char* filename)
log_text(str,true); log_text(str,true);
/* Close WAV file (if there was one) */ if (wavinfo.fd < 0)
if (wavinfo.fd >= 0) { {
close_wav();
log_text("Wrote /test.wav",true);
} else {
/* Display benchmark information */ /* Display benchmark information */
rb->snprintf(str,sizeof(str),"Decode time - %d.%02ds",(int)ticks/100,(int)ticks%100); rb->snprintf(str,sizeof(str),"Decode time - %d.%02ds",(int)ticks/100,(int)ticks%100);
log_text(str,true); log_text(str,true);
@ -628,11 +624,16 @@ static enum plugin_status test_track(char* filename)
log_text(str,true); log_text(str,true);
} }
/* Write an empty line to the log */ res = PLUGIN_OK;
log_text("",true);
rb->backlight_on();
exit: exit:
rb->backlight_on();
if (fd >= 0)
{
rb->close(fd);
}
return res; return res;
} }
@ -761,16 +762,25 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
if (!(entry->attribute & ATTR_DIRECTORY)) { if (!(entry->attribute & ATTR_DIRECTORY)) {
rb->snprintf(filename,sizeof(filename),"%s%s",dirpath,entry->d_name); rb->snprintf(filename,sizeof(filename),"%s%s",dirpath,entry->d_name);
test_track(filename); test_track(filename);
log_text("", true);
} }
/* Read next entry */ /* Read next entry */
entry = rb->readdir(dir); entry = rb->readdir(dir);
} }
rb->closedir(dir);
} }
} else { } else {
/* Just test the file */ /* Just test the file */
res = test_track(parameter); res = test_track(parameter);
/* Close WAV file (if there was one) */
if (wavinfo.fd >= 0) {
close_wav();
log_text("Wrote /test.wav",true);
}
while (rb->button_get(true) != TESTCODEC_EXITBUTTON); while (rb->button_get(true) != TESTCODEC_EXITBUTTON);
} }