Skip to content

Commit 040b3e9

Browse files
author
Philippe Waroquiers
committed
Fix leaks of 'per program space' and 'per inferior' ada task data.
Valgrind reports leaks such as the below. Fix these leaks by changing ada_tasks_pspace_data_handle and ada_tasks_inferior_data_handle to use the 'with_cleanup' register variant. Tested on debian/amd64 natively and under Valgrind. ==26346== 56 bytes in 1 blocks are definitely lost in loss record 631 of 3,249 ==26346== at 0x4C2C4CC: operator new(unsigned long) (vg_replace_malloc.c:344) ==26346== by 0x38F911: get_ada_tasks_inferior_data(inferior*) (ada-tasks.c:281) ==26346== by 0x38FA3F: ada_tasks_invalidate_inferior_data (ada-tasks.c:1362) ==26346== by 0x38FA3F: ada_tasks_new_objfile_observer(objfile*) (ada-tasks.c:1411) ==26346== by 0x60CBC5: operator() (functional:2127) ==26346== by 0x60CBC5: notify (observable.h:106) ==26346== by 0x60CBC5: clear_symtab_users(enum_flags<symfile_add_flag>) (symfile.c:2903) ... ==26346== 104 bytes in 1 blocks are definitely lost in loss record 984 of 3,249 ==26346== at 0x4C2E0BC: calloc (vg_replace_malloc.c:762) ==26346== by 0x4056F0: xcalloc (common-utils.c:84) ==26346== by 0x38F8AE: xcnew<ada_tasks_pspace_data> (poison.h:122) ==26346== by 0x38F8AE: get_ada_tasks_pspace_data(program_space*) (ada-tasks.c:253) ==26346== by 0x38FA77: ada_tasks_invalidate_pspace_data (ada-tasks.c:1354) ==26346== by 0x38FA77: ada_tasks_new_objfile_observer(objfile*) (ada-tasks.c:1394) ==26346== by 0x60CBC5: operator() (functional:2127) ==26346== by 0x60CBC5: notify (observable.h:106) ... gdb/ChangeLog 2019-02-18 Philippe Waroquiers <philippe.waroquiers@skynet.be> * ada-task.c (_initialize_tasks): Use 'with_cleanup' register variant for ada_tasks_pspace_data_handle and ada_tasks_inferior_data_handle. (ada_tasks_pspace_data_cleanup): New function. (ada_tasks_inferior_data_cleanup): New function.
1 parent a31b8bd commit 040b3e9

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

gdb/ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2019-02-18 Philippe Waroquiers <philippe.waroquiers@skynet.be>
2+
3+
* ada-task.c (_initialize_tasks): Use 'with_cleanup' register
4+
variant for ada_tasks_pspace_data_handle and
5+
ada_tasks_inferior_data_handle.
6+
(ada_tasks_pspace_data_cleanup): New function.
7+
(ada_tasks_inferior_data_cleanup): New function.
8+
19
2019-02-17 Tom Tromey <tom@tromey.com>
210

311
* macrotab.h (macro_source_fullname): Return a std::string.

gdb/ada-tasks.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ struct ada_tasks_pspace_data
161161
/* Key to our per-program-space data. */
162162
static const struct program_space_data *ada_tasks_pspace_data_handle;
163163

164+
/* A cleanup routine for our per-program-space data. */
165+
static void
166+
ada_tasks_pspace_data_cleanup (struct program_space *pspace, void *arg)
167+
{
168+
struct ada_tasks_pspace_data *data
169+
= (struct ada_tasks_pspace_data *) arg;
170+
xfree (data);
171+
}
172+
164173
/* The kind of data structure used by the runtime to store the list
165174
of Ada tasks. */
166175

@@ -285,6 +294,15 @@ get_ada_tasks_inferior_data (struct inferior *inf)
285294
return data;
286295
}
287296

297+
/* A cleanup routine for our per-inferior data. */
298+
static void
299+
ada_tasks_inferior_data_cleanup (struct inferior *inf, void *arg)
300+
{
301+
struct ada_tasks_inferior_data *data
302+
= (struct ada_tasks_inferior_data *) arg;
303+
delete data;
304+
}
305+
288306
/* Return the task number of the task whose thread is THREAD, or zero
289307
if the task could not be found. */
290308

@@ -1414,8 +1432,12 @@ ada_tasks_new_objfile_observer (struct objfile *objfile)
14141432
void
14151433
_initialize_tasks (void)
14161434
{
1417-
ada_tasks_pspace_data_handle = register_program_space_data ();
1418-
ada_tasks_inferior_data_handle = register_inferior_data ();
1435+
ada_tasks_pspace_data_handle
1436+
= register_program_space_data_with_cleanup (NULL,
1437+
ada_tasks_pspace_data_cleanup);
1438+
ada_tasks_inferior_data_handle
1439+
= register_inferior_data_with_cleanup (NULL,
1440+
ada_tasks_inferior_data_cleanup);
14191441

14201442
/* Attach various observers. */
14211443
gdb::observers::normal_stop.attach (ada_tasks_normal_stop_observer);

0 commit comments

Comments
 (0)