Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] varobj.c memory leaks
@ 2001-11-08  6:33 Keith Seitz
  2001-11-08  8:10 ` Fernando Nasser
  0 siblings, 1 reply; 3+ messages in thread
From: Keith Seitz @ 2001-11-08  6:33 UTC (permalink / raw)
  To: gdb-patches

Hi,

I was looking at c++ problems in varobj when I noticed that we had a few
memory leaks.

*_name_of_child allocates memory for the return result. The result must be
xfreed when no longer needed.

I've tested this on gdb.mi/mi-var-display.exp, gdb.mi/mi-watch.exp,
gdb.gdbtk/c_variable.exp, and gdb.gdbtk/cpp_variable.exp, and it has no
regressions.

Keith

ChangeLog
2001-11-20  Keith Seitz  <keiths@redhat.com>

	* varobj.c (c_value_of_child): Release memory for "name" when
	finshed using it.
	(c_type_of_child): Likewise.
	(cplus_value_of_child): Isolate the use of name_of_child to
	one case that needs it.
	Release memory for "name" when finished using it.

Patch
Index: varobj.c
===================================================================
RCS file: /cvs/src/src/gdb/varobj.c,v
retrieving revision 1.24
diff -u -p -r1.24 varobj.c
--- varobj.c	2001/11/19 19:44:04	1.24
+++ varobj.c	2001/11/20 17:03:27
@@ -1977,6 +1977,7 @@ c_value_of_child (struct varobj *parent,
   if (value != NULL)
     release_value (value);

+  xfree (name);
   return value;
 }

@@ -2019,6 +2020,7 @@ c_type_of_child (struct varobj *parent,
       break;
     }

+  xfree (name);
   return type;
 }

@@ -2281,7 +2283,6 @@ cplus_value_of_child (struct varobj *par
 {
   struct type *type;
   struct value *value;
-  char *name;

   if (CPLUS_FAKE_CHILD (parent))
     type = get_type_deref (parent->parent);
@@ -2289,19 +2290,22 @@ cplus_value_of_child (struct varobj *par
     type = get_type_deref (parent);

   value = NULL;
-  name = name_of_child (parent, index);

   if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
       ((TYPE_CODE (type)) == TYPE_CODE_UNION))
     {
       if (CPLUS_FAKE_CHILD (parent))
 	{
+	  char *name;
 	  struct value *temp = parent->parent->value;

+	  name = name_of_child (parent, index);
 	  gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
 				"cplus_structure");
 	  if (value != NULL)
 	    release_value (value);
+
+	  xfree (name);
 	}
       else if (index >= TYPE_N_BASECLASSES (type))
 	{


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFA] varobj.c memory leaks
  2001-11-08  6:33 [RFA] varobj.c memory leaks Keith Seitz
@ 2001-11-08  8:10 ` Fernando Nasser
  2001-11-08  8:59   ` Keith Seitz
  0 siblings, 1 reply; 3+ messages in thread
From: Fernando Nasser @ 2001-11-08  8:10 UTC (permalink / raw)
  To: Keith Seitz; +Cc: gdb-patches

Keith Seitz wrote:
> 
> Hi,
> 
> I was looking at c++ problems in varobj when I noticed that we had a few
> memory leaks.
> 
> *_name_of_child allocates memory for the return result. The result must be
> xfreed when no longer needed.
> 
> I've tested this on gdb.mi/mi-var-display.exp, gdb.mi/mi-watch.exp,
> gdb.gdbtk/c_variable.exp, and gdb.gdbtk/cpp_variable.exp, and it has no
> regressions.
> 
> Keith
> 

Thanks.  Please check it in.

F.


> ChangeLog
> 2001-11-20  Keith Seitz  <keiths@redhat.com>
> 
>         * varobj.c (c_value_of_child): Release memory for "name" when
>         finshed using it.
>         (c_type_of_child): Likewise.
>         (cplus_value_of_child): Isolate the use of name_of_child to
>         one case that needs it.
>         Release memory for "name" when finished using it.
> 
> Patch
> Index: varobj.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/varobj.c,v
> retrieving revision 1.24
> diff -u -p -r1.24 varobj.c
> --- varobj.c    2001/11/19 19:44:04     1.24
> +++ varobj.c    2001/11/20 17:03:27
> @@ -1977,6 +1977,7 @@ c_value_of_child (struct varobj *parent,
>    if (value != NULL)
>      release_value (value);
> 
> +  xfree (name);
>    return value;
>  }
> 
> @@ -2019,6 +2020,7 @@ c_type_of_child (struct varobj *parent,
>        break;
>      }
> 
> +  xfree (name);
>    return type;
>  }
> 
> @@ -2281,7 +2283,6 @@ cplus_value_of_child (struct varobj *par
>  {
>    struct type *type;
>    struct value *value;
> -  char *name;
> 
>    if (CPLUS_FAKE_CHILD (parent))
>      type = get_type_deref (parent->parent);
> @@ -2289,19 +2290,22 @@ cplus_value_of_child (struct varobj *par
>      type = get_type_deref (parent);
> 
>    value = NULL;
> -  name = name_of_child (parent, index);
> 
>    if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
>        ((TYPE_CODE (type)) == TYPE_CODE_UNION))
>      {
>        if (CPLUS_FAKE_CHILD (parent))
>         {
> +         char *name;
>           struct value *temp = parent->parent->value;
> 
> +         name = name_of_child (parent, index);
>           gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
>                                 "cplus_structure");
>           if (value != NULL)
>             release_value (value);
> +
> +         xfree (name);
>         }
>        else if (index >= TYPE_N_BASECLASSES (type))
>         {

-- 
Fernando Nasser
Red Hat Canada Ltd.                     E-Mail:  fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario   M4P 2C9


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFA] varobj.c memory leaks
  2001-11-08  8:10 ` Fernando Nasser
@ 2001-11-08  8:59   ` Keith Seitz
  0 siblings, 0 replies; 3+ messages in thread
From: Keith Seitz @ 2001-11-08  8:59 UTC (permalink / raw)
  To: gdb-patches

On Tue, 20 Nov 2001, Fernando Nasser wrote:

> Keith Seitz wrote:
> >
> > Hi,
> >
> > I was looking at c++ problems in varobj when I noticed that we had a few
> > memory leaks.
> >
> > *_name_of_child allocates memory for the return result. The result must be
> > xfreed when no longer needed.
> >
> > I've tested this on gdb.mi/mi-var-display.exp, gdb.mi/mi-watch.exp,
> > gdb.gdbtk/c_variable.exp, and gdb.gdbtk/cpp_variable.exp, and it has no
> > regressions.
> >
> > Keith
> >
>
> Thanks.  Please check it in.

Done. Thanks for the quick response. Now on to get my C++ changes for
varobj in! :-)

Keith

> > ChangeLog
> > 2001-11-20  Keith Seitz  <keiths@redhat.com>
> >
> >         * varobj.c (c_value_of_child): Release memory for "name" when
> >         finshed using it.
> >         (c_type_of_child): Likewise.
> >         (cplus_value_of_child): Isolate the use of name_of_child to
> >         one case that needs it.
> >         Release memory for "name" when finished using it.
> >
> > Patch
> > Index: varobj.c
> > ===================================================================
> > RCS file: /cvs/src/src/gdb/varobj.c,v
> > retrieving revision 1.24
> > diff -u -p -r1.24 varobj.c
> > --- varobj.c    2001/11/19 19:44:04     1.24
> > +++ varobj.c    2001/11/20 17:03:27
> > @@ -1977,6 +1977,7 @@ c_value_of_child (struct varobj *parent,
> >    if (value != NULL)
> >      release_value (value);
> >
> > +  xfree (name);
> >    return value;
> >  }
> >
> > @@ -2019,6 +2020,7 @@ c_type_of_child (struct varobj *parent,
> >        break;
> >      }
> >
> > +  xfree (name);
> >    return type;
> >  }
> >
> > @@ -2281,7 +2283,6 @@ cplus_value_of_child (struct varobj *par
> >  {
> >    struct type *type;
> >    struct value *value;
> > -  char *name;
> >
> >    if (CPLUS_FAKE_CHILD (parent))
> >      type = get_type_deref (parent->parent);
> > @@ -2289,19 +2290,22 @@ cplus_value_of_child (struct varobj *par
> >      type = get_type_deref (parent);
> >
> >    value = NULL;
> > -  name = name_of_child (parent, index);
> >
> >    if (((TYPE_CODE (type)) == TYPE_CODE_STRUCT) ||
> >        ((TYPE_CODE (type)) == TYPE_CODE_UNION))
> >      {
> >        if (CPLUS_FAKE_CHILD (parent))
> >         {
> > +         char *name;
> >           struct value *temp = parent->parent->value;
> >
> > +         name = name_of_child (parent, index);
> >           gdb_value_struct_elt (NULL, &value, &temp, NULL, name, NULL,
> >                                 "cplus_structure");
> >           if (value != NULL)
> >             release_value (value);
> > +
> > +         xfree (name);
> >         }
> >        else if (index >= TYPE_N_BASECLASSES (type))
> >         {
>
> --
> Fernando Nasser
> Red Hat Canada Ltd.                     E-Mail:  fnasser@redhat.com
> 2323 Yonge Street, Suite #300
> Toronto, Ontario   M4P 2C9
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-11-20 18:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-08  6:33 [RFA] varobj.c memory leaks Keith Seitz
2001-11-08  8:10 ` Fernando Nasser
2001-11-08  8:59   ` Keith Seitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox