File libcdaudio-closedir.diff of Package libcdaudio

--- src/coverart.c
+++ src/coverart.c
@@ -279,6 +279,7 @@
 {
   DIR *coverart_dir;
   int index, coverart_fd;
+  int retval = 0;
   char root_dir[256], procbuffer[256], id[CDINDEX_ID_SIZE];
   struct stat st;
   struct dirent *d;
@@ -319,25 +320,32 @@
 	art->art_mime_type[0] = '\0';
 	 
       snprintf(procbuffer, 256, "%s/%s", root_dir, d->d_name);
-      if(stat(procbuffer, &st) < 0)
-	return -1;
+      if(stat(procbuffer, &st) < 0) {
+	retval = -1;
+	goto cleanup;
+      }
 	 
       art->art_length = st.st_size;
-      if((coverart_fd = open(procbuffer, O_RDONLY)) < 0)
-	return -1;
+      if((coverart_fd = open(procbuffer, O_RDONLY)) < 0) {
+	retval = -1;
+	goto cleanup;
+      }
 	 
-      if(read(coverart_fd, art->art_image, art->art_length) < 0)
-	return -1;
+      if(read(coverart_fd, art->art_image, art->art_length) < 0) {
+	retval = -1;
+      }
 	 
       art->art_present = 1;
-	 
-      return 0;
+      goto cleanup;
     }
   }
    
   art->art_present = 0;
+
+cleanup:
+  closedir(coverart_dir);
    
-  return 0;
+  return retval;
 }
 
 /* Write cover art to local cache */