This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[commit] Code cleanup: py-auto-load.c: Use cleanups
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 19 Mar 2012 19:25:49 +0100
- Subject: [commit] Code cleanup: py-auto-load.c: Use cleanups
Hi,
maybe it is not such a code cleanup but rather a fix, there can happen errors
inside the wrapped code as I see now.
Anyway it was difficult to manipulate this code not using cleanups.
Checked in.
Thanks,
Jan
http://sourceware.org/ml/gdb-cvs/2012-03/msg00236.html
--- src/gdb/ChangeLog 2012/03/19 18:19:23 1.14027
+++ src/gdb/ChangeLog 2012/03/19 18:23:51 1.14028
@@ -1,5 +1,13 @@
2012-03-19 Jan Kratochvil <jan.kratochvil@redhat.com>
+ Code cleanup.
+ * python/py-auto-load.c (source_section_scripts): New variable back_to.
+ Turn fclose and xfree calls into make_cleanup_fclose and make_cleanup
+ with xfree.
+ (auto_load_objfile_script): Turn fclose into make_cleanup_fclose.
+
+2012-03-19 Jan Kratochvil <jan.kratochvil@redhat.com>
+
* NEWS: Describe new options --init-command=FILE, -ix and
--init-eval-command=COMMAND, -iex.
* main.c (struct cmdarg): New enum items CMDARG_INIT_FILE and
--- src/gdb/python/py-auto-load.c 2012/01/26 21:54:45 1.18
+++ src/gdb/python/py-auto-load.c 2012/03/19 18:23:52 1.19
@@ -254,6 +254,7 @@
FILE *stream;
char *full_path;
int opened, in_hash_table;
+ struct cleanup *back_to;
if (*p != 1)
{
@@ -286,6 +287,13 @@
opened = find_and_open_script (file, 1 /*search_path*/,
&stream, &full_path);
+ back_to = make_cleanup (null_cleanup, NULL);
+ if (opened)
+ {
+ make_cleanup_fclose (stream);
+ make_cleanup (xfree, full_path);
+ }
+
/* If one script isn't found it's not uncommon for more to not be
found either. We don't want to print an error message for each
script, too much noise. Instead, we print the warning once and tell
@@ -313,9 +321,9 @@
/* If this file is not currently loaded, load it. */
if (! in_hash_table)
source_python_script_for_objfile (objfile, stream, full_path);
- fclose (stream);
- xfree (full_path);
}
+
+ do_cleanups (back_to);
}
}
@@ -420,6 +428,8 @@
{
struct auto_load_pspace_info *pspace_info;
+ make_cleanup_fclose (input);
+
/* Add this script to the hash table too so "info auto-load-scripts"
can print it. */
pspace_info =
@@ -432,7 +442,6 @@
and these scripts are required to be idempotent under multiple
loads anyway. */
source_python_script_for_objfile (objfile, input, debugfile);
- fclose (input);
}
do_cleanups (cleanups);