diff options
author | Simon Marchi <simon.marchi@ericsson.com> | 2018-08-07 17:43:08 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@ericsson.com> | 2018-08-07 17:43:08 -0400 |
commit | 528e15722bf67d126e17218708c0314bcfadbf6a (patch) | |
tree | 8b17bb0ea9569e150917b27be97b3ecfdc96fe62 /gdb/nat | |
parent | 96d68bd48c77fa44e517c3380ee8f224cbce00e5 (diff) | |
download | gdb-528e15722bf67d126e17218708c0314bcfadbf6a.zip gdb-528e15722bf67d126e17218708c0314bcfadbf6a.tar.gz gdb-528e15722bf67d126e17218708c0314bcfadbf6a.tar.bz2 |
Replace some uses of xstrprintf with string_printf
This patch replaces some simple uses of xstrprintf with with
string_printf, removing the need to do manual memory freeing.
The change in ada-lang.c fixes an apparent memory leak.
Regtested on the buildbot.
gdb/ChangeLog:
* common/filestuff.h (gdb_fopen_cloexec): New overload.
(gdb_open_cloexec): Likewise.
* nat/linux-osdata.c (command_from_pid): Use string_printf.
(commandline_from_pid): Likewise.
(linux_xfer_osdata_threads): Likewise.
(linux_xfer_osdata_fds): Likewise.
* ada-lang.c (is_package_name): Likewise.
* auxv.c (procfs_xfer_auxv): Likewise.
* breakpoint.c (print_one_breakpoint_location): Use
uiout::field_fmt.
(print_one_catch_solib): Use string_printf.
* coff-pe-read.c (add_pe_exported_sym): Likewise.
(add_pe_forwarded_sym): Likewise.
* dwarf2read.c (create_type_unit_group): Likewise.
(build_error_marker_type): Likewise.
* infcall.c (get_function_name): Likewise.
* valprint.c (print_converted_chars_to_obstack): Likewise.
* xtensa-tdep.c (xtensa_register_type): Likewise.
Diffstat (limited to 'gdb/nat')
-rw-r--r-- | gdb/nat/linux-osdata.c | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c index 2323dcc..9850cad 100644 --- a/gdb/nat/linux-osdata.c +++ b/gdb/nat/linux-osdata.c @@ -115,7 +115,7 @@ linux_common_core_of_thread (ptid_t ptid) static void command_from_pid (char *command, int maxlen, PID_T pid) { - char *stat_path = xstrprintf ("/proc/%lld/stat", pid); + std::string stat_path = string_printf ("/proc/%lld/stat", pid); gdb_file_up fp = gdb_fopen_cloexec (stat_path, "r"); command[0] = '\0'; @@ -142,8 +142,6 @@ command_from_pid (char *command, int maxlen, PID_T pid) } command[maxlen - 1] = '\0'; /* Ensure string is null-terminated. */ - - xfree (stat_path); } /* Returns the command-line of the process with the given PID. The @@ -152,7 +150,7 @@ command_from_pid (char *command, int maxlen, PID_T pid) static char * commandline_from_pid (PID_T pid) { - char *pathname = xstrprintf ("/proc/%lld/cmdline", pid); + std::string pathname = xstrprintf ("/proc/%lld/cmdline", pid); char *commandline = NULL; gdb_file_up f = gdb_fopen_cloexec (pathname, "r"); @@ -198,8 +196,6 @@ commandline_from_pid (PID_T pid) } } - xfree (pathname); - return commandline; } @@ -572,16 +568,16 @@ linux_xfer_osdata_threads (gdb_byte *readbuf, && S_ISDIR (statbuf.st_mode)) { DIR *dirp2; - char *pathname; PID_T pid; char command[32]; - pathname = xstrprintf ("/proc/%s/task", dp->d_name); + std::string pathname + = string_printf ("/proc/%s/task", dp->d_name); pid = atoi (dp->d_name); command_from_pid (command, sizeof (command), pid); - dirp2 = opendir (pathname); + dirp2 = opendir (pathname.c_str ()); if (dirp2) { @@ -615,8 +611,6 @@ linux_xfer_osdata_threads (gdb_byte *readbuf, closedir (dirp2); } - - xfree (pathname); } } @@ -781,7 +775,6 @@ linux_xfer_osdata_fds (gdb_byte *readbuf, if (stat (procentry, &statbuf) == 0 && S_ISDIR (statbuf.st_mode)) { - char *pathname; DIR *dirp2; PID_T pid; char command[32]; @@ -789,8 +782,9 @@ linux_xfer_osdata_fds (gdb_byte *readbuf, pid = atoi (dp->d_name); command_from_pid (command, sizeof (command), pid); - pathname = xstrprintf ("/proc/%s/fd", dp->d_name); - dirp2 = opendir (pathname); + std::string pathname + = string_printf ("/proc/%s/fd", dp->d_name); + dirp2 = opendir (pathname.c_str ()); if (dirp2) { @@ -798,15 +792,17 @@ linux_xfer_osdata_fds (gdb_byte *readbuf, while ((dp2 = readdir (dirp2)) != NULL) { - char *fdname; char buf[1000]; ssize_t rslt; if (!isdigit (dp2->d_name[0])) continue; - fdname = xstrprintf ("%s/%s", pathname, dp2->d_name); - rslt = readlink (fdname, buf, sizeof (buf) - 1); + std::string fdname + = string_printf ("%s/%s", pathname.c_str (), + dp2->d_name); + rslt = readlink (fdname.c_str (), buf, + sizeof (buf) - 1); if (rslt >= 0) buf[rslt] = '\0'; @@ -826,8 +822,6 @@ linux_xfer_osdata_fds (gdb_byte *readbuf, closedir (dirp2); } - - xfree (pathname); } } |