You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rivet-dev@tcl.apache.org by Massimo Manghi <mx...@apache.org> on 2022/02/14 11:14:17 UTC

memory leak in Rivet_Var

I think I spotted a memory leak in function Rivet_Var 
(src/mod_rivet_ng/rivetCore.c)

Whenever one of the ::rivet::var forms 'var (all | list | names)' ('var 
get' excluded) returns an empty string the result value is created calling

result = Tcl_NewStringObj("",-1);

in every case variable 'result' was already pointing to a Tcl_Obj 
created at the beginning of the function, after the basic argument 
checks are performed. The pointer to such object is lost and its memory 
never freed (the function relies on Tcl_SetObjResult which internally 
calls Tcl_IncrRefCount and Tcl_DecrRefCount)


  -- Massimo

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: memory leak in Rivet_Var

Posted by Massimo Manghi <ma...@rivetweb.org>.
I would plan a maintenance release. I've also added a new feature to
'::rivet::var all' that allows an extra optional argument that is
interpreted as a dictionary of default values (in the same way the
'::rivet::var get' command has an optional default value argument).
That's why I noticed the memory leak. 

The code in the master branch has also new versions of the TEA tcl.m4
and install-sh scripts

  -- Massimo

On Mon, Feb 14, 2022 at 09:55:07AM -0500, Brice Hamon wrote:
> Thanks Massimo.
> Good catch.
> We will need to get a patch, or a maintenance release?
> 
> Thank you
> Brice.
> 
> On Mon, Feb 14, 2022 at 9:39 AM Massimo Manghi <mx...@apache.org> wrote:
> 
> > I think I spotted a memory leak in function Rivet_Var
> > (src/mod_rivet_ng/rivetCore.c)
> >
> > Whenever one of the ::rivet::var forms 'var (all | list | names)' ('var
> > get' excluded) returns an empty string the result value is created calling
> >
> > result = Tcl_NewStringObj("",-1);
> >
> > in every case variable 'result' was already pointing to a Tcl_Obj
> > created at the beginning of the function, after the basic argument
> > checks are performed. The pointer to such object is lost and its memory
> > never freed (the function relies on Tcl_SetObjResult which internally
> > calls Tcl_IncrRefCount and Tcl_DecrRefCount)
> >
> >
> >   -- Massimo
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
> > For additional commands, e-mail: rivet-dev-help@tcl.apache.org
> >
> >

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: memory leak in Rivet_Var

Posted by Brice Hamon <no...@gmail.com>.
Thanks Massimo.
Good catch.
We will need to get a patch, or a maintenance release?

Thank you
Brice.

On Mon, Feb 14, 2022 at 9:39 AM Massimo Manghi <mx...@apache.org> wrote:

> I think I spotted a memory leak in function Rivet_Var
> (src/mod_rivet_ng/rivetCore.c)
>
> Whenever one of the ::rivet::var forms 'var (all | list | names)' ('var
> get' excluded) returns an empty string the result value is created calling
>
> result = Tcl_NewStringObj("",-1);
>
> in every case variable 'result' was already pointing to a Tcl_Obj
> created at the beginning of the function, after the basic argument
> checks are performed. The pointer to such object is lost and its memory
> never freed (the function relies on Tcl_SetObjResult which internally
> calls Tcl_IncrRefCount and Tcl_DecrRefCount)
>
>
>   -- Massimo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
> For additional commands, e-mail: rivet-dev-help@tcl.apache.org
>
>