From 13e46b9a4e665ccc9ae6d99f63e240f98f67d184 Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Mon, 19 Jan 2015 12:57:44 +0100 Subject: [PATCH] [Ada] pspace_data->sym_cache is always NULL The Ada symbol cache has been designed to have one instance of that of that cache per program space, and for each instance to be created on-demand. ada_get_symbol_cache is the function responsible for both lookup and creation on demand. Unfortunately, ada_get_symbol_cache forgot to store the reference to newly created caches, thus causing it to: - Leak old caches; - Allocate a new cache each time the cache is being searched or a new entry is to be inserted. This patch fixes the issue by avoiding the use of the local variable, which indirectly allowed the bug to happen. We manipulate the reference in the program-space data instead. gdb/ChangeLog: PR gdb/17854: * ada-lang.c (ada_get_symbol_cache): Set pspace_data->sym_cache when allocating a new one. --- gdb/ada-lang.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index f5753f1..2c98191 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -4404,15 +4404,14 @@ static struct ada_symbol_cache * ada_get_symbol_cache (struct program_space *pspace) { struct ada_pspace_data *pspace_data = get_ada_pspace_data (pspace); - struct ada_symbol_cache *sym_cache = pspace_data->sym_cache; - if (sym_cache == NULL) + if (pspace_data->sym_cache == NULL) { - sym_cache = XCNEW (struct ada_symbol_cache); - ada_init_symbol_cache (sym_cache); + pspace_data->sym_cache = XCNEW (struct ada_symbol_cache); + ada_init_symbol_cache (pspace_data->sym_cache); } - return sym_cache; + return pspace_data->sym_cache; } /* Clear all entries from the symbol cache. */ -- 1.9.1