Fix a resource leak in the profile include support
authorGreg Hudson <ghudson@mit.edu>
Sun, 29 Aug 2010 22:35:41 +0000 (22:35 +0000)
committerGreg Hudson <ghudson@mit.edu>
Sun, 29 Aug 2010 22:35:41 +0000 (22:35 +0000)
ticket: 6761

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24274 dc483132-0cff-0310-8789-dd5450dbe970

src/util/profile/prof_parse.c

index 7f3d4c9d490dd1a3316d4191b6bdfe879c2918d7..85bd91227beabaa62e4e6263b375ad759f2ee486 100644 (file)
@@ -241,7 +241,7 @@ static errcode_t parse_include_dir(char *dirname, struct parse_state *state)
 {
     DIR     *dir;
     char    *pathname;
-    errcode_t retval;
+    errcode_t retval = 0;
     struct dirent *ent;
 
     dir = opendir(dirname);
@@ -250,14 +250,17 @@ static errcode_t parse_include_dir(char *dirname, struct parse_state *state)
     while ((ent = readdir(dir)) != NULL) {
         if (!valid_name(ent->d_name))
             continue;
-        if (asprintf(&pathname, "%s/%s", dirname, ent->d_name) < 0)
-            return ENOMEM;
+        if (asprintf(&pathname, "%s/%s", dirname, ent->d_name) < 0) {
+            retval = ENOMEM;
+            break;
+        }
         retval = parse_include_file(pathname, state);
         free(pathname);
         if (retval)
-            return retval;
+            break;
     }
-    return 0;
+    closedir(dir);
+    return retval;
 }
 
 static errcode_t parse_line(char *line, struct parse_state *state)