This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository legacy-imlib2.

View the commit online.

commit 829632a735b315b6589e3ec36cf73ca27d460711
Author: Kim Woelders <[email protected]>
AuthorDate: Tue Jan 31 19:16:29 2023 +0100

    __imlib_FileDir(): Fix missing closedir() on OOM
    
    Noted by NRK.
    
    And some cosmetics.
---
 src/lib/file.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/lib/file.c b/src/lib/file.c
index d8e4d64..bfb5500 100644
--- a/src/lib/file.c
+++ b/src/lib/file.c
@@ -207,26 +207,27 @@ __imlib_FileDir(const char *dir, int *num)
    struct dirent      *dp;
 
    if ((!dir) || (!*dir))
-      return 0;
+      return NULL;
+
    dirp = opendir(dir);
    if (!dirp)
-     {
-        *num = 0;
-        return NULL;
-     }
+      return NULL;
+
    /* count # of entries in dir (worst case) */
    for (dirlen = 0; readdir(dirp) != NULL; dirlen++)
       ;
    if (!dirlen)
      {
         closedir(dirp);
-        *num = dirlen;
         return NULL;
      }
-   names = (char **)malloc(dirlen * sizeof(char *));
 
+   names = malloc(dirlen * sizeof(char *));
    if (!names)
-      return NULL;
+     {
+        closedir(dirp);
+        return NULL;
+     }
 
    rewinddir(dirp);
    for (i = 0; i < dirlen;)
@@ -234,17 +235,19 @@ __imlib_FileDir(const char *dir, int *num)
         dp = readdir(dirp);
         if (!dp)
            break;
+
         if ((strcmp(dp->d_name, ".")) && (strcmp(dp->d_name, "..")))
           {
              names[i] = strdup(dp->d_name);
              i++;
           }
      }
+   closedir(dirp);
 
    if (i < dirlen)
       dirlen = i;               /* dir got shorter... */
-   closedir(dirp);
    *num = dirlen;
+
    /* do a simple bubble sort here to alphanumberic it */
    while (!done)
      {
@@ -262,6 +265,7 @@ __imlib_FileDir(const char *dir, int *num)
                }
           }
      }
+
    return names;
 }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to