lsflib/src/getdir.c
changeset 136 d82f65e902d0
parent 121 fef2ccfa7b12
child 150 75133486ba7e
--- a/lsflib/src/getdir.c
+++ b/lsflib/src/getdir.c
@@ -48,29 +48,23 @@
     }
 
     while ((entry = readdir (directory))) {
-        list = (char *)malloc (strlen (root) + 1 + strlen (entry->d_name) + 1);
+        if ((!strcmp (entry->d_name, ".")) || (!strcmp (entry->d_name, "..")))
+            continue;
 
-        if (list == NULL) {
-            perror ("malloc");
-            return;
-        }
-
+        list = malloc (strlen (root) + 1 + strlen (entry->d_name) + 1);
         sprintf (list, "%s/%s", root, entry->d_name);
 
-        if (!strcmp (entry->d_name, "."))
-            continue;
-        if (!strcmp (entry->d_name, ".."))
-            continue;
         if (isDir (list)) {
             printf ("Directory: %s\n", list);
             if (recursive)
                 getdir (list, recursive);
+            free (list);
             continue;
         }
 
         printf ("%s\n", list);
+        free (list);
     }
 
-    free (list);
     closedir (directory);
 }