Jan Kratochvil dcb8ac2
http://sourceware.org/ml/gdb-cvs/2012-03/msg00236.html
Jan Kratochvil dcb8ac2
Jan Kratochvil dcb8ac2
### src/gdb/ChangeLog	2012/03/19 18:19:23	1.14027
Jan Kratochvil dcb8ac2
### src/gdb/ChangeLog	2012/03/19 18:23:51	1.14028
Jan Kratochvil dcb8ac2
## -1,5 +1,13 @@
Jan Kratochvil dcb8ac2
 2012-03-19  Jan Kratochvil  <jan.kratochvil@redhat.com>
Jan Kratochvil dcb8ac2
 
Jan Kratochvil dcb8ac2
+	Code cleanup.
Jan Kratochvil dcb8ac2
+	* python/py-auto-load.c (source_section_scripts): New variable back_to.
Jan Kratochvil dcb8ac2
+	Turn fclose and xfree calls into make_cleanup_fclose and make_cleanup
Jan Kratochvil dcb8ac2
+	with xfree.
Jan Kratochvil dcb8ac2
+	(auto_load_objfile_script): Turn fclose into make_cleanup_fclose.
Jan Kratochvil dcb8ac2
+
Jan Kratochvil dcb8ac2
+2012-03-19  Jan Kratochvil  <jan.kratochvil@redhat.com>
Jan Kratochvil dcb8ac2
+
Jan Kratochvil dcb8ac2
 	* NEWS: Describe new options --init-command=FILE, -ix and
Jan Kratochvil dcb8ac2
 	--init-eval-command=COMMAND, -iex.
Jan Kratochvil dcb8ac2
 	* main.c (struct cmdarg): New enum items CMDARG_INIT_FILE and
Jan Kratochvil dcb8ac2
Index: gdb-7.3.50.20110722/gdb/python/py-auto-load.c
Jan Kratochvil dcb8ac2
===================================================================
Jan Kratochvil dcb8ac2
--- gdb-7.3.50.20110722.orig/gdb/python/py-auto-load.c	2012-04-18 23:40:45.000000000 +0200
Jan Kratochvil dcb8ac2
+++ gdb-7.3.50.20110722/gdb/python/py-auto-load.c	2012-04-18 23:43:59.643262382 +0200
Jan Kratochvil dcb8ac2
@@ -254,6 +254,7 @@ source_section_scripts (struct objfile *
Jan Kratochvil dcb8ac2
       FILE *stream;
Jan Kratochvil dcb8ac2
       char *full_path;
Jan Kratochvil dcb8ac2
       int opened, in_hash_table;
Jan Kratochvil dcb8ac2
+      struct cleanup *back_to;
Jan Kratochvil dcb8ac2
 
Jan Kratochvil dcb8ac2
       if (*p != 1)
Jan Kratochvil dcb8ac2
 	{
Jan Kratochvil dcb8ac2
@@ -286,6 +287,13 @@ source_section_scripts (struct objfile *
Jan Kratochvil dcb8ac2
       opened = find_and_open_script (file, 1 /*search_path*/,
Jan Kratochvil dcb8ac2
 				     &stream, &full_path);
Jan Kratochvil dcb8ac2
 
Jan Kratochvil dcb8ac2
+      back_to = make_cleanup (null_cleanup, NULL);
Jan Kratochvil dcb8ac2
+      if (opened)
Jan Kratochvil dcb8ac2
+	{
Jan Kratochvil dcb8ac2
+	  make_cleanup_fclose (stream);
Jan Kratochvil dcb8ac2
+	  make_cleanup (xfree, full_path);
Jan Kratochvil dcb8ac2
+	}
Jan Kratochvil dcb8ac2
+
Jan Kratochvil dcb8ac2
       /* If one script isn't found it's not uncommon for more to not be
Jan Kratochvil dcb8ac2
 	 found either.  We don't want to print an error message for each
Jan Kratochvil dcb8ac2
 	 script, too much noise.  Instead, we print the warning once and tell
Jan Kratochvil dcb8ac2
@@ -313,9 +321,9 @@ Use `info auto-load-scripts [REGEXP]' to
Jan Kratochvil dcb8ac2
 	  /* If this file is not currently loaded, load it.  */
Jan Kratochvil dcb8ac2
 	  if (! in_hash_table)
Jan Kratochvil dcb8ac2
 	    source_python_script_for_objfile (objfile, stream, full_path);
Jan Kratochvil dcb8ac2
-	  fclose (stream);
Jan Kratochvil dcb8ac2
-	  free (full_path);
Jan Kratochvil dcb8ac2
 	}
Jan Kratochvil dcb8ac2
+
Jan Kratochvil dcb8ac2
+      do_cleanups (back_to);
Jan Kratochvil dcb8ac2
     }
Jan Kratochvil dcb8ac2
 }
Jan Kratochvil dcb8ac2
 
Jan Kratochvil dcb8ac2
@@ -420,6 +428,8 @@ auto_load_objfile_script (struct objfile
Jan Kratochvil dcb8ac2
     {
Jan Kratochvil dcb8ac2
       struct auto_load_pspace_info *pspace_info;
Jan Kratochvil dcb8ac2
 
Jan Kratochvil dcb8ac2
+      make_cleanup_fclose (input);
Jan Kratochvil dcb8ac2
+
Jan Kratochvil dcb8ac2
       /* Add this script to the hash table too so "info auto-load-scripts"
Jan Kratochvil dcb8ac2
 	 can print it.  */
Jan Kratochvil dcb8ac2
       pspace_info =
Jan Kratochvil dcb8ac2
@@ -432,7 +442,6 @@ auto_load_objfile_script (struct objfile
Jan Kratochvil dcb8ac2
 	 and these scripts are required to be idempotent under multiple
Jan Kratochvil dcb8ac2
 	 loads anyway.  */
Jan Kratochvil dcb8ac2
       source_python_script_for_objfile (objfile, input, debugfile);
Jan Kratochvil dcb8ac2
-      fclose (input);
Jan Kratochvil dcb8ac2
     }
Jan Kratochvil dcb8ac2
 
Jan Kratochvil dcb8ac2
   do_cleanups (cleanups);