possible memory leak in v1.4.5

Omer Brandis <[email protected]> Tue, 23 Jul 2019 16:19:16 +0300
Newsgroups gmane.comp.gnu.prolog.bugs
Message-ID <CAN-G5z8H5Y5kfzdDTHUPuDE8rHuRFJnM0abVQFotm_mLOXNpng@mail.gmail.com>
--===============7834712196672875301==
Content-Type: multipart/alternative; boundary="000000000000bed9bc058e590a59"

--000000000000bed9bc058e590a59
Content-Type: text/plain; charset="UTF-8"

1) I seem to have encountered a memory leak.

I'm new to prolog,Gnu prolog, thus I'm hoping its my error and if so, i'd
appreciate some guidance.


I'm using gnu prolog v 1.4.5
I'm building a cpp to prolog wrapper (using gcc (Ubuntu
5.4.0-6ubuntu1~16.04.9) 5.4.0 ).
I'm trying to read a list of compounds. each compound is itself a compound
for example list = [
c1(Value1,c2(value2,c3(Value3,Value4),c3(Value5,Value6)),c2(Value7,c3(value8,Value9),c3(Value10,Value10)))
]
note that in some cases there are several occurrences of a compound/term  (
C1 has two instances of c2. c2 has 2 instances of c3)).


i've managed to :
a. execute a Pl_Query_Call to get the data
b. parse and iterate the list data (using Pl_List_Length and
Pl_Rd_Proper_List)
c. unify with c1 using Pl_Un_Compound_Check ( and access value1)
d. unify with c2 using Pl_Un_Compound_Check ( ana access values 2,7).

e. but when i add the code for unification with c3 , i encounter the
following error "Fatal Error: Segmentation Violation (bad address: 0x852)"
more specifically
unification with c3 works i access values 3 & 4 successfully, but then i
get the segfault when the second unification attempt with c2 is attempted (
so i can't access value7).

parsing c1 for all c2 compounds is done in a loop,
the same code works when unification with c3 is not present/attempted .

( i perform Pl_Mk_Variable for each itme of the 3 parameter of
Pl_Un_Compound_Check - inside the loop,
and i fear this is causing the problem. )


2) i have a question regarding memory deallocation done by Pl_end_query.
lets say for example that i have :

func1 ()
{
PlTerm ArgArray[1];
        ArgArray = Pl_Mk_Variable();
}

main
{
pl_begin_query(pl_True).

func1();

pl_end_query(PL_RECOVER).
}


how can pl_end_query(PL_RECOVER) free the memory if its address was stored
on the stack and is no longer available?


Please advise,
Omer Brandis.

--000000000000bed9bc058e590a59
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">1) I seem to have encountered a memory leak.<br><br>I&#39;=
m new to prolog,Gnu prolog, thus I&#39;m hoping its my error and if so, i&#=
39;d appreciate some guidance.<br><br><br>I&#39;m using gnu prolog v 1.4.5<=
br>I&#39;m building a cpp to prolog wrapper (using gcc (Ubuntu 5.4.0-6ubunt=
u1~16.04.9) 5.4.0 ). <br>I&#39;m trying to read a list of compounds. each c=
ompound is itself a compound<div>for example list =3D [ c1(Value1,c2(value2=
,c3(Value3,Value4),c3(Value5,Value6)),c2(Value7,c3(value8,Value9),c3(Value1=
0,Value10))) ]</div><div>note that in some cases there are several occurren=
ces of a compound/term=C2=A0 ( C1 has two instances of c2. c2 has 2 instanc=
es of c3)).</div><div><br><br>i&#39;ve managed to :<br>a. execute a Pl_Quer=
y_Call to get the data<br>b. parse and iterate the list data (using Pl_List=
_Length and Pl_Rd_Proper_List)<br>c. unify with c1 using Pl_Un_Compound_Che=
ck ( and access value1)<br>d. unify with c2 using Pl_Un_Compound_Check ( an=
a access values 2,7).<br><br>e. but when i add the code for unification wit=
h c3 , i encounter the following error &quot;Fatal Error: Segmentation Viol=
ation (bad address: 0x852)&quot; <br>more specifically<br>unification with =
c3 works i access values 3 &amp; 4 successfully, but then i get the segfaul=
t when the second unification attempt with c2 is attempted ( so i can&#39;t=
 access value7).<br><br>parsing c1 for all c2 compounds is done in a loop, =
<br>the same code works when unification with c3 is not present/attempted .=
<br><br>( i perform Pl_Mk_Variable for each itme of the 3 parameter of Pl_U=
n_Compound_Check - inside the loop, <br>and i fear this is causing the prob=
lem. ) <br><br><br>2) i have a question regarding memory deallocation done =
by Pl_end_query.<br>lets say for example that i have :<br><br>func1 ()<br>{=
<br>	PlTerm	ArgArray[1];<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 ArgArray =3D Pl_Mk_=
Variable();<br>}<br><br>main <br>{<br>	pl_begin_query(pl_True).<br><br>	fun=
c1();<br><br>	pl_end_query(PL_RECOVER).<br>}<br><br><br>how can pl_end_quer=
y(PL_RECOVER) free the memory if its address was stored on the stack and is=
 no longer available?<br><br><br>Please advise,<br>Omer Brandis.<br><br></d=
iv></div>

--000000000000bed9bc058e590a59--


--===============7834712196672875301==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KQnVnLXByb2xv
ZyBtYWlsaW5nIGxpc3QKQnVnLXByb2xvZ0BnbnUub3JnCmh0dHBzOi8vbGlzdHMuZ251Lm9yZy9t
YWlsbWFuL2xpc3RpbmZvL2J1Zy1wcm9sb2cK

--===============7834712196672875301==--