This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 1/1] Fix memleak of the pid_to_exec_file target_ops method for some platforms
- From: Hui Zhu <hui_zhu at mentor dot com>
- To: gdb-patches ml <gdb-patches at sourceware dot org>
- Date: Tue, 18 Mar 2014 00:02:08 +0800
- Subject: [PATCH 1/1] Fix memleak of the pid_to_exec_file target_ops method for some platforms
- Authentication-results: sourceware.org; auth=none
- References: <53271C09 dot 5000709 at mentor dot com>
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)
{