From c9ccf9867f322138c8468f8f7a5691b742dd976a Mon Sep 17 00:00:00 2001 From: Ailin Nemui Date: Wed, 11 Nov 2020 23:06:59 +0100 Subject: [PATCH] Make a copy of the signal arguments so we don't have to worry about the stack plug some mem leaks later copy --- src/perl/perl-signals.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/perl/perl-signals.c b/src/perl/perl-signals.c index 9dd73cdb..9f49fba8 100644 --- a/src/perl/perl-signals.c +++ b/src/perl/perl-signals.c @@ -87,8 +87,9 @@ void perl_signal_args_to_c(void (*callback)(void *, int, void **), void *cb_arg, GSList *v_gslist; GList *v_glist; } saved_args[SIGNAL_MAX_ARGUMENTS]; - void *p[SIGNAL_MAX_ARGUMENTS]; - PERL_SIGNAL_ARGS_REC *rec; + AV *aargs; + void *p[SIGNAL_MAX_ARGUMENTS]; + PERL_SIGNAL_ARGS_REC *rec; char *arglist[MAX_FORMAT_PARAMS]; size_t n; @@ -203,10 +204,13 @@ void perl_signal_args_to_c(void (*callback)(void *, int, void **), void *cb_arg, p[n] = NULL; } + /* make a copy of the stack now, since the callback might change it */ + aargs = av_make(n_args, args); + callback(cb_arg, n_args, p); for (n = 0; n < SIGNAL_MAX_ARGUMENTS && n < n_args && rec->args[n] != NULL; ++n) { - SV *arg = args[n]; + SV *arg = *av_fetch(aargs, n, 0); if (!SvOK(arg)) { continue; @@ -245,6 +249,7 @@ void perl_signal_args_to_c(void (*callback)(void *, int, void **), void *cb_arg, g_list_free(gl); } } + av_undef(aargs); } static void perl_call_signal(PERL_SCRIPT_REC *script, SV *func,