This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[commit] fix file descriptor leak in py-auto-load.c
- From: dje at google dot com (Doug Evans)
- To: gdb-patches at sourceware dot org
- Date: Mon, 19 Sep 2011 12:02:33 -0700 (PDT)
- Subject: [commit] fix file descriptor leak in py-auto-load.c
Hi.
Committed.
2011-09-19 Doug Evans <dje@google.com>
* python/py-auto-load.c (source_section_scripts): Fix file
descriptor leak.
* python/python.c (source_python_script_for_objfile): Tweak comments.
Index: python/python.c
===================================================================
RCS file: /cvs/src/src/gdb/python/python.c,v
retrieving revision 1.72
diff -u -p -r1.72 python.c
--- python/python.c 15 Sep 2011 12:42:30 -0000 1.72
+++ python/python.c 19 Sep 2011 19:00:25 -0000
@@ -903,7 +903,10 @@ gdbpy_progspaces (PyObject *unused1, PyO
static struct objfile *gdbpy_current_objfile;
/* Set the current objfile to OBJFILE and then read STREAM,FILE as
- Python code. */
+ Python code.
+ STREAM is left open, it is up to the caller to close it.
+ If an exception occurs python will print the traceback and
+ clear the error indicator. */
void
source_python_script_for_objfile (struct objfile *objfile,
@@ -914,8 +917,6 @@ source_python_script_for_objfile (struct
cleanups = ensure_python_env (get_objfile_arch (objfile), current_language);
gdbpy_current_objfile = objfile;
- /* Note: If an exception occurs python will print the traceback and
- clear the error indicator. */
PyRun_SimpleFile (stream, file);
do_cleanups (cleanups);
Index: python/py-auto-load.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-auto-load.c,v
retrieving revision 1.12
diff -u -p -r1.12 py-auto-load.c
--- python/py-auto-load.c 4 Aug 2011 19:10:14 -0000 1.12
+++ python/py-auto-load.c 19 Sep 2011 19:00:25 -0000
@@ -296,9 +296,6 @@ source_section_scripts (struct objfile *
in_hash_table = maybe_add_script (pspace_info->loaded_scripts, file,
opened ? full_path : NULL);
- if (opened)
- free (full_path);
-
if (! opened)
{
/* We don't throw an error, the program is still debuggable. */
@@ -310,12 +307,15 @@ Use `info auto-load-scripts [REGEXP]' to
GDBPY_AUTO_SECTION_NAME, objfile->name);
pspace_info->script_not_found_warning_printed = TRUE;
}
- continue;
}
-
- /* If this file is not currently loaded, load it. */
- if (! in_hash_table)
- source_python_script_for_objfile (objfile, stream, file);
+ else
+ {
+ /* If this file is not currently loaded, load it. */
+ if (! in_hash_table)
+ source_python_script_for_objfile (objfile, stream, file);
+ fclose (stream);
+ free (full_path);
+ }
}
}