From: Kevin Buettner <kevinb@redhat.com>
To: gdb-patches@sources.redhat.com
Subject: [PATCH] Fix memory leak in solib-svr4.c
Date: Thu, 11 Mar 2004 17:36:00 -0000 [thread overview]
Message-ID: <20040311103643.4a4e170b@saguaro> (raw)
I've just committed the patch below.
It fixes a memory leak in solib-svr4.c. In enable_break(), the memory
allocated by svr4_current_sos() was never being freed.
I could have iterated over the list returned by this function and
freed each entry, but, instead, I chose to eliminate the call to
svr4_current_sos() altogether. It appears to me that the call to
svr4_current_sos() was being used for two purposes: 1) to determine
whether or not to call solib_add(), and 2) as a means for finding
the dynamic linker's base address. solib_add() makes its own call
to svr4_current_sos(), which means that svr4_current_sos() was
being invoked an extra time for no good reason (that I can see).
The code has been reorganized to instead use the master list
operated on by solib_add().
Kevin
* solist.h (master_so_list): New function.
* solib.c (master_so_list): Likewise.
* solib-svr4.c (enable_break): Iterate over so_list entries
obtained from master list instead of entries obtained directly
via svr4_current_sos().
Index: solib-svr4.c
===================================================================
RCS file: /cvs/src/src/gdb/solib-svr4.c,v
retrieving revision 1.41
diff -c -p -r1.41 solib-svr4.c
*** solib-svr4.c 21 Feb 2004 18:34:45 -0000 1.41
--- solib-svr4.c 11 Mar 2004 16:57:35 -0000
*************** enable_break (void)
*** 1004,1010 ****
char *buf;
CORE_ADDR load_addr = 0;
int load_addr_found = 0;
! struct so_list *inferior_sos;
bfd *tmp_bfd = NULL;
struct target_ops *tmp_bfd_target;
int tmp_fd = -1;
--- 1004,1010 ----
char *buf;
CORE_ADDR load_addr = 0;
int load_addr_found = 0;
! struct so_list *so;
bfd *tmp_bfd = NULL;
struct target_ops *tmp_bfd_target;
int tmp_fd = -1;
*************** enable_break (void)
*** 1047,1069 ****
target will also close the underlying bfd. */
tmp_bfd_target = target_bfd_reopen (tmp_bfd);
! /* If the entry in _DYNAMIC for the dynamic linker has already
! been filled in, we can read its base address from there. */
! inferior_sos = svr4_current_sos ();
! if (inferior_sos)
{
! /* Connected to a running target. Update our shared library table. */
! solib_add (NULL, 0, NULL, auto_solib_add);
! }
! while (inferior_sos)
! {
! if (strcmp (buf, inferior_sos->so_original_name) == 0)
{
load_addr_found = 1;
! load_addr = LM_ADDR (inferior_sos);
break;
}
! inferior_sos = inferior_sos->next;
}
/* Otherwise we find the dynamic linker's base address by examining
--- 1047,1065 ----
target will also close the underlying bfd. */
tmp_bfd_target = target_bfd_reopen (tmp_bfd);
! /* On a running target, we can get the dynamic linker's base
! address from the shared library table. */
! solib_add (NULL, 0, NULL, auto_solib_add);
! so = master_so_list ();
! while (so)
{
! if (strcmp (buf, so->so_original_name) == 0)
{
load_addr_found = 1;
! load_addr = LM_ADDR (so);
break;
}
! so = so->next;
}
/* Otherwise we find the dynamic linker's base address by examining
Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.63
diff -c -p -r1.63 solib.c
*** solib.c 28 Feb 2004 18:04:37 -0000 1.63
--- solib.c 11 Mar 2004 16:57:35 -0000
*************** free_so (struct so_list *so)
*** 333,338 ****
--- 333,346 ----
}
+ /* Return address of first so_list entry in master shared object list. */
+ struct so_list *
+ master_so_list (void)
+ {
+ return so_list_head;
+ }
+
+
/* A small stub to get us past the arg-passing pinhole of catch_errors. */
static int
Index: solist.h
===================================================================
RCS file: /cvs/src/src/gdb/solist.h,v
retrieving revision 1.8
diff -c -p -r1.8 solist.h
*** solist.h 24 Feb 2003 19:11:04 -0000 1.8
--- solist.h 11 Mar 2004 16:57:35 -0000
*************** struct target_so_ops
*** 107,113 ****
--- 107,117 ----
};
+ /* Free the memory associated with a (so_list *). */
void free_so (struct so_list *so);
+
+ /* Return address of first so_list entry in master shared object list. */
+ struct so_list *master_so_list (void);
/* Find solib binary file and open it. */
extern int solib_open (char *in_pathname, char **found_pathname);
WARNING: multiple messages have this Message-ID
From: Kevin Buettner <kevinb@redhat.com>
To: gdb-patches@sources.redhat.com
Subject: [PATCH] Fix memory leak in solib-svr4.c
Date: Fri, 19 Mar 2004 00:09:00 -0000 [thread overview]
Message-ID: <20040311103643.4a4e170b@saguaro> (raw)
Message-ID: <20040319000900.Ri4a1m6343Mt_plfFMkvg_kxRW67K3jkNgS2DIA832A@z> (raw)
I've just committed the patch below.
It fixes a memory leak in solib-svr4.c. In enable_break(), the memory
allocated by svr4_current_sos() was never being freed.
I could have iterated over the list returned by this function and
freed each entry, but, instead, I chose to eliminate the call to
svr4_current_sos() altogether. It appears to me that the call to
svr4_current_sos() was being used for two purposes: 1) to determine
whether or not to call solib_add(), and 2) as a means for finding
the dynamic linker's base address. solib_add() makes its own call
to svr4_current_sos(), which means that svr4_current_sos() was
being invoked an extra time for no good reason (that I can see).
The code has been reorganized to instead use the master list
operated on by solib_add().
Kevin
* solist.h (master_so_list): New function.
* solib.c (master_so_list): Likewise.
* solib-svr4.c (enable_break): Iterate over so_list entries
obtained from master list instead of entries obtained directly
via svr4_current_sos().
Index: solib-svr4.c
===================================================================
RCS file: /cvs/src/src/gdb/solib-svr4.c,v
retrieving revision 1.41
diff -c -p -r1.41 solib-svr4.c
*** solib-svr4.c 21 Feb 2004 18:34:45 -0000 1.41
--- solib-svr4.c 11 Mar 2004 16:57:35 -0000
*************** enable_break (void)
*** 1004,1010 ****
char *buf;
CORE_ADDR load_addr = 0;
int load_addr_found = 0;
! struct so_list *inferior_sos;
bfd *tmp_bfd = NULL;
struct target_ops *tmp_bfd_target;
int tmp_fd = -1;
--- 1004,1010 ----
char *buf;
CORE_ADDR load_addr = 0;
int load_addr_found = 0;
! struct so_list *so;
bfd *tmp_bfd = NULL;
struct target_ops *tmp_bfd_target;
int tmp_fd = -1;
*************** enable_break (void)
*** 1047,1069 ****
target will also close the underlying bfd. */
tmp_bfd_target = target_bfd_reopen (tmp_bfd);
! /* If the entry in _DYNAMIC for the dynamic linker has already
! been filled in, we can read its base address from there. */
! inferior_sos = svr4_current_sos ();
! if (inferior_sos)
{
! /* Connected to a running target. Update our shared library table. */
! solib_add (NULL, 0, NULL, auto_solib_add);
! }
! while (inferior_sos)
! {
! if (strcmp (buf, inferior_sos->so_original_name) == 0)
{
load_addr_found = 1;
! load_addr = LM_ADDR (inferior_sos);
break;
}
! inferior_sos = inferior_sos->next;
}
/* Otherwise we find the dynamic linker's base address by examining
--- 1047,1065 ----
target will also close the underlying bfd. */
tmp_bfd_target = target_bfd_reopen (tmp_bfd);
! /* On a running target, we can get the dynamic linker's base
! address from the shared library table. */
! solib_add (NULL, 0, NULL, auto_solib_add);
! so = master_so_list ();
! while (so)
{
! if (strcmp (buf, so->so_original_name) == 0)
{
load_addr_found = 1;
! load_addr = LM_ADDR (so);
break;
}
! so = so->next;
}
/* Otherwise we find the dynamic linker's base address by examining
Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.63
diff -c -p -r1.63 solib.c
*** solib.c 28 Feb 2004 18:04:37 -0000 1.63
--- solib.c 11 Mar 2004 16:57:35 -0000
*************** free_so (struct so_list *so)
*** 333,338 ****
--- 333,346 ----
}
+ /* Return address of first so_list entry in master shared object list. */
+ struct so_list *
+ master_so_list (void)
+ {
+ return so_list_head;
+ }
+
+
/* A small stub to get us past the arg-passing pinhole of catch_errors. */
static int
Index: solist.h
===================================================================
RCS file: /cvs/src/src/gdb/solist.h,v
retrieving revision 1.8
diff -c -p -r1.8 solist.h
*** solist.h 24 Feb 2003 19:11:04 -0000 1.8
--- solist.h 11 Mar 2004 16:57:35 -0000
*************** struct target_so_ops
*** 107,113 ****
--- 107,117 ----
};
+ /* Free the memory associated with a (so_list *). */
void free_so (struct so_list *so);
+
+ /* Return address of first so_list entry in master shared object list. */
+ struct so_list *master_so_list (void);
/* Find solib binary file and open it. */
extern int solib_open (char *in_pathname, char **found_pathname);
next reply other threads:[~2004-03-11 17:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-11 17:36 Kevin Buettner [this message]
2004-03-19 0:09 ` Kevin Buettner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040311103643.4a4e170b@saguaro \
--to=kevinb@redhat.com \
--cc=gdb-patches@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox