Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: memory leak (2): named reference
- X-seq: zsh-workers 53026
- From: "Jun. T" <takimoto-j@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: memory leak (2): named reference
- Date: Wed, 7 Aug 2024 01:03:28 +0900
- Archived-at: <https://zsh.org/workers/53026>
- In-reply-to: <CAH+w=7ZMX79_o6nVknsK7ViWD4Gp-uuSJjiEhUA6+cZmopF_Tg@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <0D741AF4-0E8C-4FAA-B45A-E787958FCC41@kba.biglobe.ne.jp> <CAH+w=7ZMX79_o6nVknsK7ViWD4Gp-uuSJjiEhUA6+cZmopF_Tg@mail.gmail.com>
> 2024/08/06 7:53, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Fri, Jun 28, 2024 at 3:19 AM Jun T <takimoto-j@xxxxxxxxxxxxxxxxx> wrote:
>
>> % cat test3
>> typeset -n ref
>> for ref in one ref
>> do; done
>
>> test3 also causes two memory leaks.
>> One is the same as test2
>> In the other, 4 bytes ("ref", allocated by ztrdup() at params.c:6329)
(yes, what was leaking was 4 bytes for "one")
>> are lost. This is caused by aborting the loop by the self reference
Sorry I was wrong. The leak was not due to the "self-reference" error.
The following gives no error but still causes the leak:
% cat test4
typeset -n ref
for ref in a b2 c2345
do; done
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?
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