[gnome-db] Newbie question: do why I get this memory leak?
silvioprog <[email protected]> Thu, 26 Jan 2017 23:16:52 -0300
| Newsgroups | gmane.comp.gnome.db |
|---|---|
| Message-ID | <CAKq_V2LYPkAwo+-BQ479=u_VVdETCnoLcjskJfkK7ne9ioWXag@mail.gmail.com> |
--===============1308598023429077000==
Content-Type: multipart/alternative; boundary=001a113dc21684c0c405470a117e
--001a113dc21684c0c405470a117e
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hello masters, I'm newbie here.
Well, I need to develop a DB application, so libgda will help me a lot in
that task. However, doing some two basic tests, I found memory in both:
#include <libgda.h>
int main() {
GdaConnection *connection;
g_print("CONNECTING\n");
connection =3D gda_connection_open_from_dsn("calvaris", NULL,
GDA_CONNECTION_OPTIONS_READ_ONLY, NULL);
if (!connection) {
g_print("CONNECTION FAILED\n");
return EXIT_FAILURE;
}
g_print("CONNECTED\n");
g_object_unref(G_OBJECT (connection));
return EXIT_SUCCESS;
}
result:
CONNECTING
CONNECTION FAILED
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D6364=3D=3DERROR: LeakSanitizer: detected memory leaks
Direct leak of 72 byte(s) in 3 object(s) allocated from:
#0 0x7fa242cd0cdd in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/li=
b
lsan.so.0+0xccdd)
#1 0x7fa242a02780 in g_malloc0 (/lib/x86_64-linux-gnu/libglib
-2.0.so.0+0x4f780)
Indirect leak of 10 byte(s) in 1 object(s) allocated from:
#0 0x7fa242cd0795 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/li=
b
lsan.so.0+0xc795)
#1 0x7fa242a02728 in g_malloc (/lib/x86_64-linux-gnu/libglib
-2.0.so.0+0x4f728)
SUMMARY: LeakSanitizer: 82 byte(s) leaked in 4 allocation(s).
Process finished with exit code 23
Same leak using a valid connection:
#include <libgda.h>
int main() {
GdaConnection *connection;
g_print("CONNECTING\n");
connection =3D gda_connection_open_from_string("SQLite",
"DB_DIR=3D.;DB_NAME=3Dtest.sqlite3", NULL, GDA_CONNECTION_OPTIONS_NONE,
NULL);
if (!connection) {
g_print("CONNECTION FAILED\n");
return EXIT_FAILURE;
}
g_print("CONNECTED\n");
g_object_unref(G_OBJECT (connection));
return EXIT_SUCCESS;
}
result:
CONNECTING
CONNECTED
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D6734=3D=3DERROR: LeakSanitizer: detected memory leaks
Direct leak of 72 byte(s) in 3 object(s) allocated from:
#0 0x7f4f60ea3cdd in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/li=
b
lsan.so.0+0xccdd)
#1 0x7f4f60bd5780 in g_malloc0 (/lib/x86_64-linux-gnu/libglib
-2.0.so.0+0x4f780)
Indirect leak of 10 byte(s) in 1 object(s) allocated from:
#0 0x7f4f60ea3795 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/li=
b
lsan.so.0+0xc795)
#1 0x7f4f60bd5728 in g_malloc (/lib/x86_64-linux-gnu/libglib
-2.0.so.0+0x4f728)
SUMMARY: LeakSanitizer: 82 byte(s) leaked in 4 allocation(s).
Process finished with exit code 23
Why?! :-/
My CMake file:
cmake_minimum_required(VERSION 3.6)
project(testes)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_FLAGS "-g -fsanitize=3Dleak")
add_definitions(-I/usr/local/include/libgda-5.0)
add_definitions(-I/usr/local/include/libgda-5.0/libgda)
add_definitions(-I/usr/include/glib-2.0)
add_definitions(-I/usr/lib/x86_64-linux-gnu/glib-2.0/include)
add_definitions(-I/usr/include/libxml2)
set(SOURCE_FILES main.c)
add_executable(testes ${SOURCE_FILES})
target_link_libraries(testes pthread glib-2.0 gobject-2.0 gda-5.0)
My environment:
OS Xubuntu 16.04 64 bits
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
$ pkg-config glib-2.0 libgda-5.0 --modversion
2.48.1
5.2.4
Thank you!
--=20
Silvio Cl=C3=A9cio
--001a113dc21684c0c405470a117e
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><span style=3D"font-size:12.8px">Hello masters, I'm ne=
wbie here.</span><div style=3D"font-size:12.8px"><div><br></div><div>Well, =
I need to develop a DB application, so libgda will help me a lot in that ta=
sk. However, doing some two basic tests, I found memory in both:</div><div>=
<pre style=3D"white-space:pre-wrap;color:rgb(0,0,0);font-family:"dejav=
u sans mono""><font size=3D"1"><span style=3D"color:rgb(128,128,0)">#i=
nclude</span><span style=3D"color:rgb(0,128,0);font-weight:bold"> <libgd=
a.h><br></span><span style=3D"color:rgb(0,128,0);font-weight:bold"><br><=
/span><span style=3D"color:rgb(0,0,128);font-weight:bold">int </span>main()=
{<br> <span style=3D"color:rgb(55,31,128)">GdaConnection </span>*connec=
tion;<br> g_print(<span style=3D"color:rgb(0,128,0);font-weight:bold">&q=
uot;CONNECTING</span><span style=3D"color:rgb(0,0,128);font-weight:bold">\n=
</span><span style=3D"color:rgb(0,128,0);font-weight:bold">"</span>);<=
br> connection =3D gda_connection_open_from_dsn(<span style=3D"color:rgb=
(0,128,0);font-weight:bold">"<wbr>calvaris"</span>, <span style=
=3D"color:rgb(31,84,46);font-weight:bold">NULL</span>, <span style=3D"color=
:rgb(102,14,122);font-weight:bold;font-style:italic">GDA_CONNECTION_OPTIONS=
_READ_ON<wbr>LY</span>, <span style=3D"color:rgb(31,84,46);font-weight:bold=
">NULL</span>);<br> <span style=3D"color:rgb(0,0,128);font-weight:bold">=
if </span>(!connection) {<br> g_print(<span style=3D"color:rgb(0,128=
,0);font-weight:bold">"CONNECTION FAILED</span><span style=3D"color:rg=
b(0,0,128);font-weight:bold">\n</span><span style=3D"color:rgb(0,128,0);fon=
t-weight:bold">"</span>);<br> <span style=3D"color:rgb(0,0,128)=
;font-weight:bold">return </span><span style=3D"color:rgb(31,84,46);font-we=
ight:bold">EXIT_FAILURE</span>;<br> }<br> g_print(<span style=3D"colo=
r:rgb(0,128,0);font-weight:bold">"CONNECTED</span><span style=3D"color=
:rgb(0,0,128);font-weight:bold">\n</span><span style=3D"color:rgb(0,128,0);=
font-weight:bold">"</span>);<br> g_object_unref(<span style=3D"colo=
r:rgb(31,84,46);font-weight:bold">G_OBJECT </span>(connection));<br> <sp=
an style=3D"color:rgb(0,0,128);font-weight:bold">return </span><span style=
=3D"color:rgb(31,84,46);font-weight:bold">EXIT_SUCCESS</span>;<br>}</font><=
/pre></div><div>result:</div><div><br></div><div><div><font face=3D"monospa=
ce, monospace" size=3D"1">CONNECTING</font></div><div><font face=3D"monospa=
ce, monospace" size=3D"1">CONNECTION FAILED</font></div><div><font face=3D"=
monospace, monospace" size=3D"1"><br></font></div><div><font face=3D"monosp=
ace, monospace" size=3D"1">=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<wbr>=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<wbr>=3D=3D=
=3D=3D=3D</font></div><div><font face=3D"monospace, monospace" size=3D"1">=
=3D=3D6364=3D=3DERROR: LeakSanitizer: detected memory leaks</font></div><di=
v><font face=3D"monospace, monospace" size=3D"1"><br></font></div><div><fon=
t face=3D"monospace, monospace" size=3D"1">Direct leak of 72 byte(s) in 3 o=
bject(s) allocated from:</font></div><div><font face=3D"monospace, monospac=
e" size=3D"1">=C2=A0 =C2=A0 #0 0x7fa242cd0cdd in __interceptor_calloc (/usr=
/lib/x86_64-linux-gnu/lib<wbr>lsan.so.0+0xccdd)</font></div><div><font face=
=3D"monospace, monospace" size=3D"1">=C2=A0 =C2=A0 #1 0x7fa242a02780 in g_m=
alloc0 (/lib/x86_64-linux-gnu/libglib<wbr>-2.0.so.0+0x4f780)</font></div><d=
iv><font face=3D"monospace, monospace" size=3D"1"><br></font></div><div><fo=
nt face=3D"monospace, monospace" size=3D"1">Indirect leak of 10 byte(s) in =
1 object(s) allocated from:</font></div><div><font face=3D"monospace, monos=
pace" size=3D"1">=C2=A0 =C2=A0 #0 0x7fa242cd0795 in __interceptor_malloc (/=
usr/lib/x86_64-linux-gnu/lib<wbr>lsan.so.0+0xc795)</font></div><div><font f=
ace=3D"monospace, monospace" size=3D"1">=C2=A0 =C2=A0 #1 0x7fa242a02728 in =
g_malloc (/lib/x86_64-linux-gnu/libglib<wbr>-2.0.so.0+0x4f728)</font></div>=
<div><font face=3D"monospace, monospace" size=3D"1"><br></font></div><div><=
font face=3D"monospace, monospace" size=3D"1">SUMMARY: LeakSanitizer: 82 by=
te(s) leaked in 4 allocation(s).</font></div><div><font face=3D"monospace, =
monospace" size=3D"1"><br></font></div><div><font face=3D"monospace, monosp=
ace" size=3D"1">Process finished with exit code 23</font></div></div><div><=
br></div><div>Same leak using a valid connection:</div><div><pre style=3D"w=
hite-space:pre-wrap;color:rgb(0,0,0);font-family:"dejavu sans mono&quo=
t;"><font size=3D"1"><span style=3D"color:rgb(128,128,0)">#include</span><s=
pan style=3D"color:rgb(0,128,0);font-weight:bold"> <libgda.h><br></sp=
an><span style=3D"color:rgb(0,128,0);font-weight:bold"><br></span><span sty=
le=3D"color:rgb(0,0,128);font-weight:bold">int </span>main() {<br> <span=
style=3D"color:rgb(55,31,128)">GdaConnection </span>*connection;<br> g_=
print(<span style=3D"color:rgb(0,128,0);font-weight:bold">"CONNECTING<=
/span><span style=3D"color:rgb(0,0,128);font-weight:bold">\n</span><span st=
yle=3D"color:rgb(0,128,0);font-weight:bold">"</span>);<br> connecti=
on =3D gda_connection_open_from_strin<wbr>g(<span style=3D"color:rgb(0,128,=
0);font-weight:bold">"SQLite"</span>, <span style=3D"color:rgb(0,=
128,0);font-weight:bold">"DB_DIR=3D.;DB_NAME=3Dtest.sqlite3<wbr>"=
</span>, <span style=3D"color:rgb(31,84,46);font-weight:bold">NULL</span>, =
<span style=3D"color:rgb(102,14,122);font-weight:bold;font-style:italic">GD=
A_CONNECTION_OPTIONS_NONE</span>, <span style=3D"color:rgb(31,84,46);font-w=
eight:bold">NULL</span>);<br> <span style=3D"color:rgb(0,0,128);font-wei=
ght:bold">if </span>(!connection) {<br> g_print(<span style=3D"color=
:rgb(0,128,0);font-weight:bold">"CONNECTION FAILED</span><span style=
=3D"color:rgb(0,0,128);font-weight:bold">\n</span><span style=3D"color:rgb(=
0,128,0);font-weight:bold">"</span>);<br> <span style=3D"color:=
rgb(0,0,128);font-weight:bold">return </span><span style=3D"color:rgb(31,84=
,46);font-weight:bold">EXIT_FAILURE</span>;<br> }<br> g_print(<span s=
tyle=3D"color:rgb(0,128,0);font-weight:bold">"CONNECTED</span><span st=
yle=3D"color:rgb(0,0,128);font-weight:bold">\n</span><span style=3D"color:r=
gb(0,128,0);font-weight:bold">"</span>);<br> g_object_unref(<span s=
tyle=3D"color:rgb(31,84,46);font-weight:bold">G_OBJECT </span>(connection))=
;<br> <span style=3D"color:rgb(0,0,128);font-weight:bold">return </span>=
<span style=3D"color:rgb(31,84,46);font-weight:bold">EXIT_SUCCESS</span>;<b=
r>}</font></pre></div><div>result:</div><div><br></div><div><div><font size=
=3D"1" face=3D"monospace, monospace">CONNECTING</font></div><div><font size=
=3D"1" face=3D"monospace, monospace">CONNECTED</font></div><div><font size=
=3D"1" face=3D"monospace, monospace"><br></font></div><div><font size=3D"1"=
face=3D"monospace, monospace">=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<wbr>=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<wbr>=
=3D=3D=3D=3D=3D</font></div><div><font size=3D"1" face=3D"monospace, monosp=
ace">=3D=3D6734=3D=3DERROR: LeakSanitizer: detected memory leaks</font></di=
v><div><font size=3D"1" face=3D"monospace, monospace"><br></font></div><div=
><font size=3D"1" face=3D"monospace, monospace">Direct leak of 72 byte(s) i=
n 3 object(s) allocated from:</font></div><div><font size=3D"1" face=3D"mon=
ospace, monospace">=C2=A0 =C2=A0 #0 0x7f4f60ea3cdd in __interceptor_calloc =
(/usr/lib/x86_64-linux-gnu/lib<wbr>lsan.so.0+0xccdd)</font></div><div><font=
size=3D"1" face=3D"monospace, monospace">=C2=A0 =C2=A0 #1 0x7f4f60bd5780 i=
n g_malloc0 (/lib/x86_64-linux-gnu/libglib<wbr>-2.0.so.0+0x4f780)</font></d=
iv><div><font size=3D"1" face=3D"monospace, monospace"><br></font></div><di=
v><font size=3D"1" face=3D"monospace, monospace">Indirect leak of 10 byte(s=
) in 1 object(s) allocated from:</font></div><div><font size=3D"1" face=3D"=
monospace, monospace">=C2=A0 =C2=A0 #0 0x7f4f60ea3795 in __interceptor_mall=
oc (/usr/lib/x86_64-linux-gnu/lib<wbr>lsan.so.0+0xc795)</font></div><div><f=
ont size=3D"1" face=3D"monospace, monospace">=C2=A0 =C2=A0 #1 0x7f4f60bd572=
8 in g_malloc (/lib/x86_64-linux-gnu/libglib<wbr>-2.0.so.0+0x4f728)</font><=
/div><div><font size=3D"1" face=3D"monospace, monospace"><br></font></div><=
div><font size=3D"1" face=3D"monospace, monospace">SUMMARY: LeakSanitizer: =
82 byte(s) leaked in 4 allocation(s).</font></div><div><font size=3D"1" fac=
e=3D"monospace, monospace"><br></font></div><div><font size=3D"1" face=3D"m=
onospace, monospace">Process finished with exit code 23</font></div></div><=
div><br></div><div>Why?! :-/</div><div><br></div><div>My CMake file:</div><=
div><pre style=3D"white-space:pre-wrap;color:rgb(0,0,0);font-family:"d=
ejavu sans mono""><pre style=3D"white-space:pre-wrap;font-family:"=
;dejavu sans mono""><font size=3D"1">cmake_minimum_required(<span styl=
e=3D"color:rgb(0,128,0);font-weight:bold">VERSION 3.6</span>)<br>project(<s=
pan style=3D"color:rgb(0,128,0);font-weight:bold">testes</span>)<br><br>set=
(<span style=3D"color:rgb(0,128,0);font-weight:bold">CMAKE_C_STANDARD 99</s=
pan>)<br><br>set(<span style=3D"color:rgb(0,128,0);font-weight:bold">CMAKE_=
C_FLAGS </span>"<span style=3D"color:rgb(0,128,0);font-weight:bold">-g=
-fsanitize=3Dleak</span>")<br><br>add_definitions(<span style=3D"colo=
r:rgb(0,128,0);font-weight:bold">-I/usr/local/i<wbr>nclude/libgda-5.0</span=
>)<br>add_definitions(<span style=3D"color:rgb(0,128,0);font-weight:bold">-=
I/usr/local/i<wbr>nclude/libgda-5.0/libgda</span>)<br>add_definitions(<span=
style=3D"color:rgb(0,128,0);font-weight:bold">-I/usr/include<wbr>/glib-2.0=
</span>)<br>add_definitions(<span style=3D"color:rgb(0,128,0);font-weight:b=
old">-I/usr/lib/x86<wbr>_64-linux-gnu/glib-2.0/include</span><wbr>)<br>add_=
definitions(<span style=3D"color:rgb(0,128,0);font-weight:bold">-I/usr/incl=
ude<wbr>/libxml2</span>)<br><br>set(<span style=3D"color:rgb(0,128,0);font-=
weight:bold">SOURCE_FILES main.c</span>)<br>add_executable(<span style=3D"c=
olor:rgb(0,128,0);font-weight:bold">testes ${SOURCE_FILES}</span>)<br>targe=
t_link_libraries(<span style=3D"color:rgb(0,128,0);font-weight:bold">testes=
pthread glib-2.0 gobject-2.0 gda-5.0</span>)</font></pre></pre></div><div>=
My environment:</div><div><br></div><div><font size=3D"1" face=3D"monospace=
, monospace">OS Xubuntu 16.04 64 bits<br></font></div><div><font size=3D"1"=
face=3D"monospace, monospace">gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ub=
untu1~16.04.4)<br></font></div><div><div><font size=3D"1" face=3D"monospace=
, monospace">$ pkg-config glib-2.0 libgda-5.0 --modversion=C2=A0</font></di=
v><div><font size=3D"1" face=3D"monospace, monospace">2.48.1</font></div><d=
iv><font size=3D"1" face=3D"monospace, monospace">5.2.4</font></div></div><=
div><br></div><div>Thank you!</div></div><div><br></div>-- <br><div class=
=3D"gmail_signature"><div dir=3D"ltr"><div>Silvio Cl=C3=A9cio</div></div></=
div>
</div>
--001a113dc21684c0c405470a117e--
--===============1308598023429077000==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
gnome-db-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/gnome-db-list
--===============1308598023429077000==--