> https://rt.cpan.org/Ticket/Display.html?id=132278
> >
> > Can you open the ticket on Tcl.pm, given that we see that it is more
> > relevant here?
>
> I have moved the existing ticket to keep the reporter informed.
> I meant to adjust the title as well but couldn't do so once it moved.
Cool! Thank you!
>
> > I will work on the fix, when time permits
>
> Thanks. Indeed there should be no rush to fix this. It
> is a benign issue that might only pose a minor annoyance to users (e.g. "Your
> program has crashed, report it?" nags from OS); unsaved data does not appear
> to
> be in jeopardy because of it.
As a workaround, you can define this environment variable in Perl, then error
goes away:
vad@bonita:~$ perl -MTcl -we '$ENV{FOO}="x";my $i=new Tcl;$i->Eval("set
env(FOO) bar");print qq/ok\n/'
ok
OTOH error message differs a bit whether or not we 'unset' this environment
variable within tcl:
vad@bonita:~$ perl -MTcl -we 'my $i=new Tcl;$i->Eval("set env(FOO) bar;unset
env(FOO)");END{print qq/in END\n/}print qq/after all\n/'
after all
in END
double free or corruption (!prev)
Aborted (core dumped)
vad@bonita:~$ perl -MTcl -we 'my $i=new Tcl;$i->Eval("set env(FOO)
bar");END{print qq/in END\n/}print qq/after all\n/'
after all
in END
free(): invalid size
Aborted (core dumped)
When Perl uses $ENV{FOO} *after* tcl then there is error again:
vad@bonita:~$ perl -MTcl -we 'my $i=new Tcl;$i->Eval("set env(FOO)
bar");$ENV{FOO}="bar";print qq/ok\n/'
free(): invalid size
Aborted (core dumped)
vad@bonita:~$ perl -MTcl -we 'my $i=new Tcl;$i->Eval("set env(FOO) bar");print
qq/ok\n/'
ok
free(): invalid size
Aborted (core dumped)
vad@bonita:~$
vad@bonita:~$ perl -MTcl -we 'my $i=new Tcl;$i->Init;$i->Eval("set env(FOO)
bar");delete $ENV{FOO};print qq/deleted FOO\n/'
free(): invalid size
Aborted (core dumped)
vad@bonita:~$ perl -MTcl -we 'my $i=new Tcl;$i->Init;$i->Eval("set env(FOO)
bar;unset env(FOO)");END{print qq/in END\n/}print qq/after all\n/'
after all
in END
double free or corruption (!prev)
Aborted (core dumped)
vad@bonita:~$
Tcl uses "ckalloc" function to allocate strings for name of environment
variable "FOO" (or a value?)
This 'ckalloc' is their helper function, which chains memory into link, so to
free it after all.
IMO If they just use "malloc" the problem will go away.
I haven't verified this assumption, but 85%-sure of it 😊
TODO list:
[x] find temporary workaround
[ ] see whether it is possible to redefine Tcl_PutEnv in Tcl.
[ ] profit
regards,
Vadim