[Ada] pspace_data->sym_cache is always NULL
authorJoel Brobecker <brobecker@adacore.com>
Mon, 2 Feb 2015 03:20:58 +0000 (07:20 +0400)
committerJoel Brobecker <brobecker@adacore.com>
Mon, 2 Feb 2015 03:22:40 +0000 (07:22 +0400)
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/ChangeLog
gdb/ada-lang.c

index 6f2f475b478d616ca69a93e8f3d0e35ee776ee02..e11ff78173b0cf1c886b2d4b4e42331394db3dc6 100644 (file)
@@ -1,3 +1,9 @@
+2015-02-02  Joel Brobecker  <brobecker@adacore.com>
+
+       PR gdb/17854:
+       * ada-lang.c (ada_get_symbol_cache): Set pspace_data->sym_cache
+       when allocating a new one.
+
 2015-02-01  Tom Tromey  <tom@tromey.com>
 
        * MAINTAINERS: Remove myself.
index f4f5bf36c8c162058cecd1510ab067367d6b4f22..921aed59575a24a9ca29ab88ebd5a7ee5ae9e85a 100644 (file)
@@ -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.  */
This page took 0.033929 seconds and 4 git commands to generate.