cline.c

changeset 4
c3acfb3b4957
parent 3
510d6b198dde
child 5
9393eff3d2f9
--- a/cline.c	Thu May 26 14:39:52 2011 +0200
+++ b/cline.c	Fri May 27 12:49:33 2011 +0200
@@ -12,6 +12,15 @@
   settings->recursive          = false;
   settings->includeSuffixes    = false;
   settings->matchesOnly        = false;
+  
+  return settings;
+}
+
+void destroy_settings_t(settings_t* settings) {
+  if (settings->suffixv != NULL) {
+    free(settings->suffixv);
+  }
+  free(settings);
 }
 
 void printHelpText(const char* prgName) {
@@ -177,13 +186,13 @@
   DIR *dir = opendir(directory);
   if (dir == NULL) {
     perror("Operation failed");
-    free(settings->suffixv);
-    free(settings);
+    destroy_settings_t(settings);
     return 1;
   }
   
   // Scan directory
   int lines = scanDirectory(dir, 0, directory, settings);
+  closedir(dir);
 
   // Print double line and line count
   #ifdef _WIN32
@@ -201,8 +210,6 @@
     printf("\n%74d lines\n", lines);
   #endif /* _WIN32 */
 
-  closedir(dir);
-  free(settings->suffixv);
-  free(settings);
+  destroy_settings_t(settings);
   return 0;
 }

mercurial