Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
memory leak (1): unset private parameter
- X-seq: zsh-workers 52980
- From: Jun T <takimoto-j@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: memory leak (1): unset private parameter
- Date: Fri, 28 Jun 2024 19:05:05 +0900
- Archived-at: <https://zsh.org/workers/52980>
- List-id: <zsh-workers.zsh.org>
valgrind found two memory leaks for which I don't have any quick fix.
This post is for the 1st problem (another post will follow for the 2nd).
% cat unset-private
() {
private foo
unset foo
}
% valgrind --leak-check=full zsh -f unset-private
32 bytes in 1 blocks are definitely lost in loss record 247 of 387
by 0x1935B9: zalloc (mem.c:966)
by 0x50B0772: makeprivate (param_private.c:138)
by 0x165D08: scanmatchtable (hashtable.c:433)
by 0x165D9E: scanhashtable (hashtable.c:449)
by 0x50B0D7A: bin_private (param_private.c:248)
param_private.c:138 is
struct gsu_closure *gsu = zalloc(sizeof(struct gsu_closure));
and this 'gsu' is saved in pm->gsu.s.
'unset foo' calls pps_unsetfn(pm, explicit=1), in param_private.c:
314 if (locallevel <= pm->level)
315 gsu->unsetfn(pm, explicit); # this sets PM_UNSET
316 if (explicit) {
317 pm->node.flags |= PM_DECLARED;
318 pm->gsu.s = (GsuScalar)c;
319 } else
320 zfree(c, sizeof(struct gsu_closure)); # NOT called
When exiting from the function, endparmscope() (indirectly) calls
unsetpm_pm(pm,, explicit=0), but it does not call
pps_unsetfn(pm, expllicit=0) since PM_UNSET is already set
(params.c:3793), and the gsu_closure is not freed.
Maybe we need to set some info in pm to inform unsetpm_pm(pm)
that gsu need be freed (but there is no flag PM_PRIVATE).
Messages sorted by:
Reverse Date,
Date,
Thread,
Author