* dwarf2loc.c (struct piece_closure) <refc>: New field.
authorTom Tromey <tromey@redhat.com>
Thu, 27 May 2010 19:14:35 +0000 (19:14 +0000)
committerTom Tromey <tromey@redhat.com>
Thu, 27 May 2010 19:14:35 +0000 (19:14 +0000)
(allocate_piece_closure): Initialize refc.
(copy_pieced_value_closure): Use refc.
(free_pieced_value_closure): Likewise.

gdb/ChangeLog
gdb/dwarf2loc.c

index 6ce98ba4624a7b1eb32ab9f17fb424b928d3b445..fd2c93663e72402a4927651ee2b88a6f45f9d31a 100644 (file)
@@ -1,3 +1,10 @@
+2010-05-27  Tom Tromey  <tromey@redhat.com>
+
+       * dwarf2loc.c (struct piece_closure) <refc>: New field.
+       (allocate_piece_closure): Initialize refc.
+       (copy_pieced_value_closure): Use refc.
+       (free_pieced_value_closure): Likewise.
+
 2010-05-27  Tom Tromey  <tromey@redhat.com>
 
        * arm-tdep.c (push_stack_item): 'contents' now const.
index a5d10f59de1d07da326f29f5e97ce87fadef4e06..79d22770d5f0696081dffa95a61e8b0643a72c4f 100644 (file)
@@ -231,6 +231,9 @@ dwarf_expr_tls_address (void *baton, CORE_ADDR offset)
 
 struct piece_closure
 {
+  /* Reference count.  */
+  int refc;
+
   /* The number of pieces used to describe this variable.  */
   int n_pieces;
 
@@ -250,6 +253,7 @@ allocate_piece_closure (int n_pieces, struct dwarf_expr_piece *pieces,
 {
   struct piece_closure *c = XZALLOC (struct piece_closure);
 
+  c->refc = 1;
   c->n_pieces = n_pieces;
   c->addr_size = addr_size;
   c->pieces = XCALLOC (n_pieces, struct dwarf_expr_piece);
@@ -747,7 +751,8 @@ copy_pieced_value_closure (struct value *v)
 {
   struct piece_closure *c = (struct piece_closure *) value_computed_closure (v);
   
-  return allocate_piece_closure (c->n_pieces, c->pieces, c->addr_size);
+  ++c->refc;
+  return c;
 }
 
 static void
@@ -755,8 +760,12 @@ free_pieced_value_closure (struct value *v)
 {
   struct piece_closure *c = (struct piece_closure *) value_computed_closure (v);
 
-  xfree (c->pieces);
-  xfree (c);
+  --c->refc;
+  if (c->refc == 0)
+    {
+      xfree (c->pieces);
+      xfree (c);
+    }
 }
 
 /* Functions for accessing a variable described by DW_OP_piece.  */