I assume 'fa' does some sort of recursive freeing of memory. instead
of removing the 'fa' call, Is a 'ras(c)' needed to increment some
reference count? Something like:
B jtadd2(J jt,F f1,F f2,C*cmd){A c,x;
if(f1==NULL) {jt->fopn+=2;R 1;};
GATV(c,LIT,1+strlen(cmd),1,0);MC(CAV(c)+1,cmd,AN(c)-1);cmd=CAV(c);RZ(ras(c));
if(jt->fopn+1>=AN(jt->fopf)){RZ(jt->fopa=ext(1,jt->fopa));
RZ(jt->fopf=ext(1,jt->fopf));}
*cmd='<';x=cstr(cmd); RZ(ras(x)); RZ(*(jt->fopn+AAV(jt->fopa) )=x);
RZ(*(jt->fopn+IAV(jt->fopf) )=(I)f1);
*cmd='>';x=cstr(cmd); RZ(ras(x)); RZ(*(jt->fopn+AAV(jt->fopa)+1)=x);
RZ(*(jt->fopn+IAV(jt->fopf)+1)=(I)f2);
fa(c); R 1;
} /* add 2 entries to jt->fopn table (for hostio); null arg commits entries */
See the added "RZ(ras(c))" in the third line. The crash goes away with this.
On Thu, Mar 8, 2018 at 4:43 AM, Chris Double <[email protected]> wrote:
> If I comment out the call to "fa(c)" in 'jtadd2' then the segfault
> goes away. Is there some memory management issue related to the
> allocation and freeing of the cmd string that is going on?
>
> On Thu, Mar 8, 2018 at 4:31 AM, Raul Miller <[email protected]> wrote:
>> Huh...
>>
>> I wonder if there's something uninitialized in libedit (or perhaps
>> some other supporting library) that needs to be initialized?
>>
>> --
>> Raul
>>
>>
>> On Wed, Mar 7, 2018 at 10:26 AM, Chris Double <[email protected]>
>> wrote:
>>> On Thu, Mar 8, 2018 at 3:29 AM, Chris Double <[email protected]>
>>> wrote:
>>>> I will investigate more though why the instability occurs.
>>>
>>> On closer debugging, it seems to be the add2 call, not the 'fdopen'.
>>> With no changes this errors:
>>>
>>> 2!:2 '/bin/ls'
>>> 10554 93976423924960 93976423925520
>>> 1 2
>>> Segmentation fault (core dumped)
>>>
>>> Note that I have to actually type in the "1 2" and it needs to have
>>> the space. I can't "up arrow" in jconsole to get the previous history
>>> value - it doesn't crash if I do that.
>>>
>>> If I comment out the 'fdopen' calls and put in dummy file pointers
>>> then I still get the crash.
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm