4
0
Эх сурвалжийг харах

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 жил өмнө
parent
commit
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 <sys/stat.h>
 #include <unistd.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
 /* np_ini_info contains the result of parsing a "locator" in the format
  * [stanza_name][@config_filename] (check_foo@/etc/foo.ini, for example)
  * [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 (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) 
 	if (is_suid_set && idpriv_temp_restore() == -1) 
 		die(STATE_UNKNOWN, "%s %s\n", _("Can't restore user permissions."), strerror(errno));
 		die(STATE_UNKNOWN, "%s %s\n", _("Can't restore user permissions."), strerror(errno));