Never return profile on error opening file
authorGreg Hudson <ghudson@mit.edu>
Mon, 25 Jul 2011 15:54:39 +0000 (15:54 +0000)
committerGreg Hudson <ghudson@mit.edu>
Mon, 25 Jul 2011 15:54:39 +0000 (15:54 +0000)
If profile_open_file() discovers a shared tree for the file, but
encounters an error when updating it, dereference the data and return
a null profile rather than returning an error and a newly broken file
object.  Otherwise we'd leak the returned file object in
profile_init().

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

src/util/profile/prof_file.c

index 988afacecf88d92a9c483b5d356d1078cb3ec0e4..b0bb087ebdc083d1452f70a8d16451079650b13b 100644 (file)
@@ -258,10 +258,15 @@ errcode_t profile_open_file(const_profile_filespec_t filespec,
         (void) k5_mutex_unlock(&g_shared_trees_mutex);
         retval = profile_update_file_data(data, NULL);
         free(expanded_filename);
+        if (retval) {
+            profile_dereference_data(data);
+            free(prf);
+            return retval;
+        }
         prf->data = data;
         *ret_prof = prf;
         scan_shared_trees_unlocked();
-        return retval;
+        return 0;
     }
     (void) k5_mutex_unlock(&g_shared_trees_mutex);
     data = profile_make_prf_data(expanded_filename);