From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] Re: Segfault with "private" parameters inside "always" block
Date: Thu, 9 Jun 2022 15:04:07 -0700 [thread overview]
Message-ID: <CAH+w=7YxctEkGm5ubDW6RPSNFVbL-C--oO=Q1gONHCSJUdWLUA@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7a4Wr3wXN5VtC=Ctmvtw=4K-6spFW8mXqC8ZaoHh87t8g@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 402 bytes --]
On Thu, Jun 9, 2022 at 2:03 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> zsh/param/private assumes the heap created in startparamscope() is the
> only active heap until endparamscope(), but "always" blocks allocate
> and free another layer of heap, which invalidates the memory "private"
> uses for the parameter GSU structures.
That was a lot simpler/more straightforward than I expected.
[-- Attachment #2: private_mem.txt --]
[-- Type: text/plain, Size: 1491 bytes --]
diff --git a/Src/Modules/param_private.c b/Src/Modules/param_private.c
index c53839152..065fa63d2 100644
--- a/Src/Modules/param_private.c
+++ b/Src/Modules/param_private.c
@@ -92,7 +92,7 @@ makeprivate(HashNode hn, UNUSED(int flags))
makeprivate_error = 1;
return;
}
- struct gsu_closure *gsu = zhalloc(sizeof(struct gsu_closure));
+ struct gsu_closure *gsu = zalloc(sizeof(struct gsu_closure));
switch (PM_TYPE(pm->node.flags)) {
case PM_SCALAR:
gsu->g = (void *)(pm->gsu.s);
@@ -269,6 +269,8 @@ pps_unsetfn(Param pm, int explicit)
gsu->unsetfn(pm, explicit);
if (explicit)
pm->gsu.s = (GsuScalar)c;
+ else
+ zfree(c, sizeof(struct gsu_closure));
}
/**/
@@ -306,6 +308,8 @@ ppi_unsetfn(Param pm, int explicit)
gsu->unsetfn(pm, explicit);
if (explicit)
pm->gsu.i = (GsuInteger)c;
+ else
+ zfree(c, sizeof(struct gsu_closure));
}
/**/
@@ -343,6 +347,8 @@ ppf_unsetfn(Param pm, int explicit)
gsu->unsetfn(pm, explicit);
if (explicit)
pm->gsu.f = (GsuFloat)c;
+ else
+ zfree(c, sizeof(struct gsu_closure));
}
/**/
@@ -381,6 +387,8 @@ ppa_unsetfn(Param pm, int explicit)
gsu->unsetfn(pm, explicit);
if (explicit)
pm->gsu.a = (GsuArray)c;
+ else
+ zfree(c, sizeof(struct gsu_closure));
}
static HashTable emptytable;
@@ -420,6 +428,8 @@ pph_unsetfn(Param pm, int explicit)
gsu->unsetfn(pm, explicit);
if (explicit)
pm->gsu.h = (GsuHash)c;
+ else
+ zfree(c, sizeof(struct gsu_closure));
}
/*
prev parent reply other threads:[~2022-06-09 22:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-09 21:03 Bart Schaefer
2022-06-09 22:04 ` Bart Schaefer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH+w=7YxctEkGm5ubDW6RPSNFVbL-C--oO=Q1gONHCSJUdWLUA@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).