<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39507 >

 section_file_read_dup() called inf_close() only in the end - many
return points (not even error related) missed it.
 It seems wrong that caller allocates inf, but section_file_read_dup()
would release it.

 Fix attached. section_file_read_dup() never release inf. Who ever
allocates inf, always releases it.

 This is ancient bug. I have seen indications about it in valgrind
outputs years ago. Until bzip2 compressed savegames leak was not
critical. But with all the buffers bz2 allocates for files, this is
easily huge leak.


 - ML

diff -Nurd -X.diff_ignore freeciv/utility/registry.c freeciv/utility/registry.c
--- freeciv/utility/registry.c	2007-08-04 18:36:14.000000000 +0300
+++ freeciv/utility/registry.c	2007-08-07 23:44:52.000000000 +0300
@@ -624,9 +624,6 @@
     }
     exit(EXIT_FAILURE);
   }
-
-  inf_close(inf);
-  inf = NULL;
   
   astr_free(&base_name);
   astr_free(&entry_name);
@@ -661,12 +658,17 @@
 {
   char real_filename[1024];
   struct inputfile *inf;
+  bool success;
 
   interpret_tilde(real_filename, sizeof(real_filename), filename);
   inf = inf_from_file(real_filename, datafilename);
 
-  return section_file_read_dup(my_section_file, real_filename,
-			       inf, TRUE, part);
+  success = section_file_read_dup(my_section_file, real_filename,
+                                  inf, TRUE, part);
+
+  inf_close(inf);
+
+  return success;
 }
 
 /**************************************************************************
@@ -677,12 +679,17 @@
 {
   char real_filename[1024];
   struct inputfile *inf;
+  bool success;
 
   interpret_tilde(real_filename, sizeof(real_filename), filename);
   inf = inf_from_file(real_filename, datafilename);
 
-  return section_file_read_dup(my_section_file, real_filename,
+  success = section_file_read_dup(my_section_file, real_filename,
 			       inf, FALSE, NULL);
+
+  inf_close(inf);
+
+  return success;
 }
 
 /**************************************************************************
@@ -691,9 +698,14 @@
 bool section_file_load_from_stream(struct section_file *my_section_file,
 				   fz_FILE * stream)
 {
+  bool success;
   struct inputfile *inf = inf_from_stream(stream, datafilename);
 
-  return section_file_read_dup(my_section_file, NULL, inf, TRUE, NULL);
+  success = section_file_read_dup(my_section_file, NULL, inf, TRUE, NULL);
+
+  inf_close(inf);
+
+  return success;
 }
 
 /**************************************************************************
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to