Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: memory leak (2): named reference



On Tue, Aug 6, 2024 at 9:03 AM Jun. T <takimoto-j@xxxxxxxxxxxxxxxxx> wrote:
>
> valgrind says 5 bytes ("a" and "b2") are lost. It seems the problem is in
> the macro SETREFNAME() used in setloopvar(). It overwrites pm->u.str
> without freeing the old value. How about the following?

This looks fine.  I'll commit it later.

> diff --git a/Src/params.c b/Src/params.c
> index f143a790f..b710ddbf6 100644
> --- a/Src/params.c
> +++ b/Src/params.c
> @@ -482,7 +482,8 @@ static initparam argvparam_pm = IPDEF9("", &pparams, NULL, \
>  #define GETREFNAME(PM) (((PM)->node.flags & PM_SPECIAL) ?      \
>                         (PM)->gsu.s->getfn(PM) : (PM)->u.str)
>  #define SETREFNAME(PM,S) (((PM)->node.flags & PM_SPECIAL) ?            \
> -                         (PM)->gsu.s->setfn(PM,(S)) : ((PM)->u.str = (S)))
> +                         (PM)->gsu.s->setfn(PM,(S)) : \
> +                         (zsfree((PM)->u.str), (PM)->u.str = (S)))
>
>  static Param argvparam;




Messages sorted by: Reverse Date, Date, Thread, Author