[1/1] Fix memleak of the pid_to_exec_file target_ops method for some platforms

Message ID 53271C80.1040103@mentor.com
State Superseded
Headers

Commit Message

Hui Zhu March 17, 2014, 4:02 p.m. UTC
  I said most of the pid_to_exec_file target_ops method for some platforms will
allocate memory for exec_file and add them to cleanup.
But some of them didn't do that.
So I make a patch to fix this memleak.

Thanks,
Hui

2014-03-17  Hui Zhu  <hui@codesourcery.com>

	* fbsd-nat.c (fbsd_pid_to_exec_file): Add make_cleanup.
	* nbsd-nat.c (nbsd_pid_to_exec_file): Ditto.
  

Comments

Hui Zhu March 18, 2014, 7:39 a.m. UTC | #1
I just posted a new version for [patch 0/1] that include this patch.
So please ignore it.

Thanks,
Hui

On 03/18/14 00:02, Hui Zhu wrote:
> I said most of the pid_to_exec_file target_ops method for some platforms will
> allocate memory for exec_file and add them to cleanup.
> But some of them didn't do that.
> So I make a patch to fix this memleak.
>
> Thanks,
> Hui
>
> 2014-03-17  Hui Zhu  <hui@codesourcery.com>
>
>      * fbsd-nat.c (fbsd_pid_to_exec_file): Add make_cleanup.
>      * nbsd-nat.c (nbsd_pid_to_exec_file): Ditto.
>
> --- a/gdb/fbsd-nat.c
> +++ b/gdb/fbsd-nat.c
> @@ -43,6 +43,8 @@ fbsd_pid_to_exec_file (struct target_ops
>     char *buf = xcalloc (len, sizeof (char));
>     char *path;
>
> +  make_cleanup (xfree, buf);
> +
>   #ifdef KERN_PROC_PATHNAME
>     int mib[4];
>
> --- a/gdb/nbsd-nat.c
> +++ b/gdb/nbsd-nat.c
> @@ -31,6 +31,8 @@ nbsd_pid_to_exec_file (struct target_ops
>     char *buf = xcalloc (len, sizeof (char));
>     char *path;
>
> +  make_cleanup (xfree, buf);
> +
>     path = xstrprintf ("/proc/%d/exe", pid);
>     if (readlink (path, buf, PATH_MAX - 1) == -1)
>       {
>
  

Patch

--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -43,6 +43,8 @@  fbsd_pid_to_exec_file (struct target_ops
    char *buf = xcalloc (len, sizeof (char));
    char *path;
  
+  make_cleanup (xfree, buf);
+
  #ifdef KERN_PROC_PATHNAME
    int mib[4];
  
--- a/gdb/nbsd-nat.c
+++ b/gdb/nbsd-nat.c
@@ -31,6 +31,8 @@  nbsd_pid_to_exec_file (struct target_ops
    char *buf = xcalloc (len, sizeof (char));
    char *path;
  
+  make_cleanup (xfree, buf);
+
    path = xstrprintf ("/proc/%d/exe", pid);
    if (readlink (path, buf, PATH_MAX - 1) == -1)
      {