Fwd: possible memory leak in v1.4.5
Omer Brandis <[email protected]> Mon, 29 Jul 2019 19:58:38 +0300
| Newsgroups | gmane.comp.gnu.prolog.bugs |
|---|---|
| Message-ID | <CAN-G5z-LLYwS__EtBv2Xwpp0zBOLEbhOJLGoasqfkgASR3cVWA@mail.gmail.com> |
--===============6757244557473529937==
Content-Type: multipart/alternative; boundary="0000000000004eb948058ed4cebf"
--0000000000004eb948058ed4cebf
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.
--0000000000004eb948058ed4cebf
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"g=
mail_attr">1) I seem to have encountered a memory leak.<br></div><div dir=
=3D"ltr"><br>I'm new to prolog,Gnu prolog, thus I'm hoping its my e=
rror and if so, i'd appreciate some guidance.<br><br><br>I'm using =
gnu prolog v 1.4.5<br>I'm building a cpp to prolog wrapper (using gcc (=
Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 ). <br>I'm trying to read a list o=
f compounds. each compound is itself a compound<div>for example list =3D [ =
c1(Value1,c2(value2,c3(Value3,Value4),c3(Value5,Value6)),c2(Value7,c3(value=
8,Value9),c3(Value10,Value10))) ]</div><div>note that in some cases there a=
re several occurrences of a compound/term=C2=A0 ( C1 has two instances of c=
2. c2 has 2 instances of c3)).</div><div><br><br>i've managed to :<br>a=
. execute a Pl_Query_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_Check ( and access value1)<br>d. unify with c2 using Pl_Un_=
Compound_Check ( ana access values 2,7).<br><br>e. but when i add the code =
for unification with c3 , i encounter the following error "Fatal Error=
: Segmentation Violation (bad address: 0x852)" <br>more specifically<b=
r>unification with c3 works i access values 3 & 4 successfully, but the=
n i get the segfault when the second unification attempt with c2 is attempt=
ed ( so i can'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_Un_Compound_Check - inside the loop, <br>and i fear this =
is causing the problem. ) <br><br><br>2) i have a question regarding memory=
deallocation done by Pl_end_query.<br>lets say for example that i have :<b=
r><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> func1();<br><br> pl_end_query(PL_RECOVER).<br>}<br><br><br>=
how can pl_end_query(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></div></div>
</div></div>
--0000000000004eb948058ed4cebf--
--===============6757244557473529937==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline
X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KQnVnLXByb2xv
ZyBtYWlsaW5nIGxpc3QKQnVnLXByb2xvZ0BnbnUub3JnCmh0dHBzOi8vbGlzdHMuZ251Lm9yZy9t
YWlsbWFuL2xpc3RpbmZvL2J1Zy1wcm9sb2cK
--===============6757244557473529937==--