Преглед на файлове

lib/parse_ini.c - Check before free, clean comment

While not likely to cause a double free, we should check that objects are not null prior to freeing, and then set to null.
Cleans up one old line of comments.
Spenser Reinhardt преди 11 години
родител
ревизия
aa3a6fe6b2
променени са 1 файла, в които са добавени 8 реда и са изтрити 4 реда
  1. 8 4
      lib/parse_ini.c

+ 8 - 4
lib/parse_ini.c

@@ -30,8 +30,6 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
-/* TODO: die like N::P if config file is not found */
-
 /* np_ini_info contains the result of parsing a "locator" in the format
  * [stanza_name][@config_filename] (check_foo@/etc/foo.ini, for example)
  */
@@ -139,8 +137,14 @@ np_arg_list* np_get_defaults(const char *locator, const char *default_section){
                 if (inifile != stdin) fclose(inifile);
         }
 
-	if (i.file != NULL) free(i.file);
-	free(i.stanza);
+	if (i.file != NULL) {
+		free(i.file);
+		i.file = NULL;
+	}
+	if (i.stanza != NULL) {
+		free(i.stanza);
+		i.stanza = NULL;
+	}
 
 	if (is_suid_set && idpriv_temp_restore() == -1) 
 		die(STATE_UNKNOWN, "%s %s\n", _("Can't restore user permissions."), strerror(errno));