aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Palka <patrick@parcs.ath.cx>2015-06-29 10:39:26 -0400
committerPatrick Palka <patrick@parcs.ath.cx>2015-08-29 08:52:50 -0400
commit8f57eec2fb31db5ab4598f09136e7978b7f84c97 (patch)
tree8827099c833d14fc0f4cca508481b82448160ecb
parent4df041938601a456999fbe9f22831e389ca74242 (diff)
downloadgdb-8f57eec2fb31db5ab4598f09136e7978b7f84c97.zip
gdb-8f57eec2fb31db5ab4598f09136e7978b7f84c97.tar.gz
gdb-8f57eec2fb31db5ab4598f09136e7978b7f84c97.tar.bz2
Use gdbarch obstack to allocate types in alloc_type_arch
For the command "gdb gdb" valgrind currently reports 100s of individual memory leaks, 500 of which originate solely out of the function alloc_type_arch. This function allocates a "struct type" associated with the given gdbarch using malloc but apparently the types allocated by this function are never freed. This patch fixes these leaks by making the function alloc_type_arch allocate these gdbarch-associated types on the gdbarch obstack instead of on the general heap. Since, from what I can tell, the types allocated by this function are all fundamental "wired-in" types, such types would not benefit from more granular memory management anyway. They would likely live as long as the gdbarch is alive so allocating them on the gdbarch obstack makes sense. With this patch, the number of individual vargrind warnings emitted for the command "gdb gdb" drops from ~800 to ~300. Tested on x86_64-unknown-linux-gnu. gdb/ChangeLog: * gdbtypes.c (alloc_type_arch): Allocate the type on the given gdbarch obstack instead of on the heap. Update commentary accordingly.
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/gdbtypes.c6
2 files changed, 9 insertions, 3 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 04749ec..e727bfb 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2015-08-29 Patrick Palka <patrick@parcs.ath.cx>
+
+ * gdbtypes.c (alloc_type_arch): Allocate the type on the given
+ gdbarch obstack instead of on the heap. Update commentary
+ accordingly.
+
2015-08-28 Joel Brobecker <brobecker@adacore.com>
GDB 7.10 released.
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 5c8e49c..8204d39 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -187,7 +187,7 @@ alloc_type (struct objfile *objfile)
/* Allocate a new GDBARCH-associated type structure and fill it
with some defaults. Space for the type structure is allocated
- on the heap. */
+ on the obstack associated with GDBARCH. */
struct type *
alloc_type_arch (struct gdbarch *gdbarch)
@@ -198,8 +198,8 @@ alloc_type_arch (struct gdbarch *gdbarch)
/* Alloc the structure and start off with all fields zeroed. */
- type = XCNEW (struct type);
- TYPE_MAIN_TYPE (type) = XCNEW (struct main_type);
+ type = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct type);
+ TYPE_MAIN_TYPE (type) = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct main_type);
TYPE_OBJFILE_OWNED (type) = 0;
TYPE_OWNER (type).gdbarch = gdbarch;