[gnome-db] Newbie question: do why I get this memory leak?



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 = 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

=================================================================
==6364==ERROR: 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/liblsan.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/liblsan.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 = gda_connection_open_from_string("SQLite", "DB_DIR=.;DB_NAME=test.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

=================================================================
==6734==ERROR: 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/liblsan.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/liblsan.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=leak")

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!

--
Silvio Clécio


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]