[Converted from Gnats 807] gdb appears to leak 2 file descriptors when it opens a program to be debugged. Both file descriptors are pointing to the file being debugged. Release: unknown Environment: RedHat 8.0 Linux on i386 arch How-To-Repeat: I used the env_audit program from http://www.web-insights.net/env_audit. It includes instructions to duplicate this in the examples directory of the tarball.
Fix: I would suggest applying a fcntl FD_CLOEXEC when opening a file.
*** Bug 14764 has been marked as a duplicate of this bug. ***
Testing a fix.
CVSROOT: /cvs/src Module name: src Changes by: tromey@sourceware.org 2013-04-22 16:46:15 Modified files: gdb : ChangeLog Makefile.in auto-load.c auxv.c config.in configure configure.ac corelow.c dwarf2read.c fork-child.c gdb_bfd.c inf-child.c linux-nat.c main.c remote-fileio.c remote.c ser-pipe.c ser-tcp.c ser-unix.c solib.c source.c tracepoint.c ui-file.c xml-support.c gdb/cli : cli-cmds.c cli-dump.c gdb/common : agent.c linux-osdata.c linux-procfs.c gdb/gdbserver : ChangeLog Makefile.in config.in configure configure.ac gdb/tui : tui-io.c Added files: gdb/common : filestuff.c filestuff.h Log message: PR gdb/7912: * Makefile.in (SFILES): Add filestuff.c (COMMON_OBS): Add filestuff.o. (filestuff.o): New target. * auto-load.c (auto_load_objfile_script_1): Use gdb_fopen_cloexec. * auxv.c (procfs_xfer_auxv): Use gdb_open_cloexec. * cli/cli-cmds.c (shell_escape): Call close_most_fds. * cli/cli-dump.c (fopen_with_cleanup): Use gdb_fopen_cloexec. * common/agent.c (gdb_connect_sync_socket): Use gdb_socket_cloexec. * common/filestuff.c: New file. * common/filestuff.h: New file. * common/linux-osdata.c (linux_common_core_of_thread) (command_from_pid, commandline_from_pid, print_source_lines) (linux_xfer_osdata_shm, linux_xfer_osdata_sem) (linux_xfer_osdata_msg, linux_xfer_osdata_modules): Use gdb_fopen_cloexec. * common/linux-procfs.c (linux_proc_get_int) (linux_proc_pid_has_state): Use gdb_fopen_cloexec. * config.in, configure: Rebuild. * configure.ac: Don't check for sys/socket.h. Check for fdwalk, pipe2. * corelow.c (core_open): Use gdb_open_cloexec. * dwarf2read.c (write_psymtabs_to_index): Use gdb_fopen_cloexec. * fork-child.c (fork_inferior): Call close_most_fds. * gdb_bfd.c (gdb_bfd_open): Use gdb_open_cloexec. * inf-child.c (inf_child_fileio_readlink): Use gdb_open_cloexec. * linux-nat.c (linux_nat_thread_name, linux_proc_pending_signals): Use gdb_fopen_cloexec. (linux_proc_xfer_partial, linux_proc_xfer_spu): Use gdb_open_cloexec. (linux_async_pipe): Use gdb_pipe_cloexec. * remote-fileio.c (remote_fileio_func_open): Use gdb_open_cloexec. * remote.c (remote_file_put, remote_file_get): Use gdb_fopen_cloexec. * ser-pipe.c (pipe_open): Use gdb_socketpair_cloexec, close_most_fds. * ser-tcp.c (net_open): Use gdb_socket_cloexec. * ser-unix.c (hardwire_open): Use gdb_open_cloexec. * solib.c (solib_find): Use gdb_open_cloexec. * source.c (openp, find_and_open_source): Use gdb_open_cloexec. * tracepoint.c (tfile_start): Use gdb_fopen_cloexec. (tfile_open): Use gdb_open_cloexec. * tui/tui-io.c (tui_initialize_io): Use gdb_pipe_cloexec. * ui-file.c (gdb_fopen): Use gdb_fopen_cloexec. * xml-support.c (xml_fetch_content_from_file): Use gdb_fopen_cloexec. * main.c (captured_main): Call notice_open_fds. gdbserver * Makefile.in (SFILES): Add filestuff.c. (OBS): Add filestuff.o. (filestuff.o): New target. * config.in, configure: Rebuild. * configure.ac: Check for fdwalk, pipe2. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.15465&r2=1.15466 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/Makefile.in.diff?cvsroot=src&r1=1.1250&r2=1.1251 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/auto-load.c.diff?cvsroot=src&r1=1.20&r2=1.21 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/auxv.c.diff?cvsroot=src&r1=1.39&r2=1.40 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/config.in.diff?cvsroot=src&r1=1.153&r2=1.154 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/configure.diff?cvsroot=src&r1=1.388&r2=1.389 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/configure.ac.diff?cvsroot=src&r1=1.200&r2=1.201 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/corelow.c.diff?cvsroot=src&r1=1.129&r2=1.130 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/dwarf2read.c.diff?cvsroot=src&r1=1.786&r2=1.787 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/fork-child.c.diff?cvsroot=src&r1=1.69&r2=1.70 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/gdb_bfd.c.diff?cvsroot=src&r1=1.18&r2=1.19 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/inf-child.c.diff?cvsroot=src&r1=1.37&r2=1.38 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/linux-nat.c.diff?cvsroot=src&r1=1.266&r2=1.267 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/main.c.diff?cvsroot=src&r1=1.124&r2=1.125 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/remote-fileio.c.diff?cvsroot=src&r1=1.47&r2=1.48 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/remote.c.diff?cvsroot=src&r1=1.543&r2=1.544 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ser-pipe.c.diff?cvsroot=src&r1=1.35&r2=1.36 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ser-tcp.c.diff?cvsroot=src&r1=1.46&r2=1.47 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ser-unix.c.diff?cvsroot=src&r1=1.42&r2=1.43 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/solib.c.diff?cvsroot=src&r1=1.170&r2=1.171 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/source.c.diff?cvsroot=src&r1=1.157&r2=1.158 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/tracepoint.c.diff?cvsroot=src&r1=1.303&r2=1.304 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ui-file.c.diff?cvsroot=src&r1=1.34&r2=1.35 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/xml-support.c.diff?cvsroot=src&r1=1.27&r2=1.28 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/cli/cli-cmds.c.diff?cvsroot=src&r1=1.154&r2=1.155 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/cli/cli-dump.c.diff?cvsroot=src&r1=1.54&r2=1.55 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/common/filestuff.c.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/common/filestuff.h.diff?cvsroot=src&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/common/agent.c.diff?cvsroot=src&r1=1.11&r2=1.12 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/common/linux-osdata.c.diff?cvsroot=src&r1=1.11&r2=1.12 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/common/linux-procfs.c.diff?cvsroot=src&r1=1.6&r2=1.7 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/gdbserver/ChangeLog.diff?cvsroot=src&r1=1.707&r2=1.708 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/gdbserver/Makefile.in.diff?cvsroot=src&r1=1.149&r2=1.150 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/gdbserver/config.in.diff?cvsroot=src&r1=1.49&r2=1.50 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/gdbserver/configure.diff?cvsroot=src&r1=1.80&r2=1.81 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/gdbserver/configure.ac.diff?cvsroot=src&r1=1.66&r2=1.67 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/tui/tui-io.c.diff?cvsroot=src&r1=1.35&r2=1.36
Fix checked in.