[DTrace-devel] [PATCH 1/4] Fix memory leak of dt_error DIFO

Kris Van Hees kris.van.hees at oracle.com
Wed Jun 9 20:15:01 PDT 2021


On Wed, Jun 09, 2021 at 09:56:52PM -0400, Eugene Loh wrote:
> Reviewed-by: Eugene Loh <eugene.loh at oracle.com>
> though to be honest I have absolutely no idea what's going on here.  I 
> simply don't see that situation changing, though!  Sure does not look 
> like a normal "memory leak."

It is pretty obscure.  The dt_error symbol is pre-defined in dt_dlibs.c but
it gets its DIFO (the executable code etc) once we are ready to load BPF
programs.  That means that when it is initally created, it does not have
any idops associated with it.  The dt_idops_difo idops are needed though
because those provide the callback hook for destructing the DIFO when the
identifier is removed.

There is no clean way to set the idops for an identifier that already exists
*except* through the dt_ident_morph() function that provides a mechanism to
morph an identifier into a specific kind, incl. the kind it already has.  So,
we morph the dt_error identifier onto itself, but with specifying the idops
that we need.

Without it, the DIFO for dt_error was never free'd.

> On 6/8/21 11:37 PM, Kris Van Hees wrote:
> > Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
> > ---
> >   libdtrace/dt_cc.c | 9 +++++++--
> >   1 file changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/libdtrace/dt_cc.c b/libdtrace/dt_cc.c
> > index 86b06237..413c1c22 100644
> > --- a/libdtrace/dt_cc.c
> > +++ b/libdtrace/dt_cc.c
> > @@ -2141,10 +2141,15 @@ dt_construct(dtrace_hdl_t *dtp, dt_probe_t *prp, uint_t cflags, dt_ident_t *idp)
> >   	dp = dt_as(yypcb);
> >   
> >   	/*
> > -	 * If we were called with an identifier, assign the DIFO to it.
> > +	 * If we were called with an identifier, assign the DIFO to it.  We
> > +	 * also must ensure that the identifier is of the correct kind (and
> > +	 * has the proper configuration) - we do this by morphing it into
> > +	 * itself.
> >   	 */
> > -	if (idp != NULL)
> > +	if (idp != NULL) {
> > +		dt_ident_morph(idp, idp->di_kind, &dt_idops_difo, dtp);
> >   		dt_ident_set_data(idp, dp);
> > +	}
> >   
> >   out:
> >   	if (dtp->dt_cdefs_fd != -1 &&
> 
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel



More information about the DTrace-devel mailing list