瀏覽代碼

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));