From c21f59090e5f0283bc3a4f719e16ea7ec4d12fa8 Mon Sep 17 00:00:00 2001 From: Magnus Holmgren Date: Sat, 15 Dec 2007 13:54:58 +0000 Subject: 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 --- apps/plugins/test_codec.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/apps/plugins/test_codec.c b/apps/plugins/test_codec.c index a1f1b29037..9cbfa70614 100644 --- a/apps/plugins/test_codec.c +++ b/apps/plugins/test_codec.c @@ -514,7 +514,7 @@ static enum plugin_status test_track(char* filename) { size_t n; int fd; - enum plugin_status res = PLUGIN_OK; + enum plugin_status res = PLUGIN_ERROR; unsigned long starttick; unsigned long ticks; unsigned long speed; @@ -538,7 +538,7 @@ static enum plugin_status test_track(char* filename) if (fd < 0) { log_text("Cannot open file",true); - return PLUGIN_ERROR; + goto exit; } 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)) { log_text("Cannot read metadata",true); - return PLUGIN_ERROR; + goto exit; } if (track.filesize > audiosize) { log_text("File too large",true); - return PLUGIN_ERROR; + goto exit; } n = rb->read(fd, audiobuf, track.filesize); @@ -563,7 +563,6 @@ static enum plugin_status test_track(char* filename) if (n != track.filesize) { log_text("Read failed.",true); - res = PLUGIN_ERROR; goto exit; } @@ -606,11 +605,8 @@ static enum plugin_status test_track(char* filename) log_text(str,true); - /* Close WAV file (if there was one) */ - if (wavinfo.fd >= 0) { - close_wav(); - log_text("Wrote /test.wav",true); - } else { + if (wavinfo.fd < 0) + { /* Display benchmark information */ rb->snprintf(str,sizeof(str),"Decode time - %d.%02ds",(int)ticks/100,(int)ticks%100); log_text(str,true); @@ -628,11 +624,16 @@ static enum plugin_status test_track(char* filename) log_text(str,true); } - /* Write an empty line to the log */ - log_text("",true); - rb->backlight_on(); + res = PLUGIN_OK; exit: + rb->backlight_on(); + + if (fd >= 0) + { + rb->close(fd); + } + return res; } @@ -761,16 +762,25 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) if (!(entry->attribute & ATTR_DIRECTORY)) { rb->snprintf(filename,sizeof(filename),"%s%s",dirpath,entry->d_name); test_track(filename); + log_text("", true); } /* Read next entry */ entry = rb->readdir(dir); } + + rb->closedir(dir); } } else { /* Just test the file */ 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); } -- cgit v1.2.3