Hello guys,
I did some memory test using valgrind, and it turns out that i found few
memory leaks. I can of course add these bug in bugzilla, but I want to have
the confirmation that these bugs aren't already fixed, and in the first
case, if the proposition is correct.
1. GdaConnectionEvent
Valgrind stack trace :
==00:00:00:07.808 3268== 820 (320 direct, 500 indirect) bytes in 10 blocks
are definitely lost in loss record 2,219 of 2,365
==00:00:00:07.808 3268== at 0x4C2B6CD: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==00:00:00:07.808 3268== by 0x4E7FA38: g_malloc (gmem.c:159)
==00:00:00:07.808 3268== by 0x4E92C72: g_slice_alloc (gslice.c:1003)
==00:00:00:07.808 3268== by 0x4E931B5: g_slice_alloc0 (gslice.c:1029)
==00:00:00:07.808 3268== by 0x5AF0889: g_type_create_instance (gtype.c:1872)
==00:00:00:07.808 3268== by 0x5AD50B8: g_object_constructor (gobject.c:1849)
==00:00:00:07.808 3268== by 0x5AD66E3: g_object_newv (gobject.c:1713)
==00:00:00:07.808 3268== by 0x5AD6EC5: g_object_new_valist (gobject.c:1830)
==00:00:00:07.808 3268== by 0x5AD71D3: g_object_new (gobject.c:1545)
==00:00:00:07.808 3268== by 0x51690CD: gda_connection_point_available_event
(gda-connection.c:2606)
==00:00:00:07.808 3268== by 0xAD17585: gda_mysql_provider_statement_execute
(gda-mysql-provider.c:2812)
==00:00:00:07.808 3268== by 0x51705F8: gda_connection_statement_execute_v
(gda-connection.c:3544)
==00:00:00:07.808 3268== by 0x517200B: gda_connection_statement_execute
(gda-connection.c:3725)
==00:00:00:07.808 3268== by 0x54F8378: ast_db_record_new_full (ast_db.c:652)
==00:00:00:07.808 3268== by 0x400909: main (main.c:24)
Correction :
--- a/providers/mysql/gda-mysql-provider.c
+++ b/providers/mysql/gda-mysql-provider.c
@@ -2826,6 +2826,11 @@ gda_mysql_provider_statement_execute
(GdaServerProvider *provider,
*last_inserted_row = make_last_inserted_set (cnc, stmt, last_row);
}
+ //Memory leak correction
+ if (event) {
+ g_object_unref(event);
+ }
2. GdaStatementSelect :
Valgrind stack trace :
==00:00:00:07.942 18943== at 0x4C29DB4: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==00:00:00:07.942 18943== by 0x4E7FAA0: g_malloc0 (gmem.c:189)
==00:00:00:07.942 18943== by 0x51E9DCD: gda_sql_statement_select_new
(gda-statement-struct-select.c:60)
==00:00:00:07.942 18943== by 0x51E3AED: gda_sql_statement_new
(gda-statement-struct.c:112)
==00:00:00:07.942 18943== by 0xAD181F7:
gda_mysql_provider_statement_execute (gda-mysql-provider.c:2019)
==00:00:00:07.942 18943== by 0x51705F8:
gda_connection_statement_execute_v (gda-connection.c:3544)
==00:00:00:07.942 18943== by 0x517200B: gda_connection_statement_execute
(gda-connection.c:3725)
==00:00:00:07.942 18943== by 0x54F8378: ast_db_record_new_full
(ast_db.c:652)
==00:00:00:07.942 18943== by 0x40095C: main (main.c:24)
3. GdaRender
at 0x4C2B6CD: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==00:00:00:07.941 18943== by 0x4E7FA38: g_malloc (gmem.c:159)
==00:00:00:07.941 18943== by 0x4E92C72: g_slice_alloc (gslice.c:1003)
==00:00:00:07.941 18943== by 0x4E93F92: g_slist_append (gslist.c:222)
==00:00:00:07.941 18943== by 0x51BF065: default_render_param_spec
(gda-statement.c:1395)
==00:00:00:07.941 18943== by 0xAD13E8E: mysql_render_expr
(gda-mysql-provider.c:1647)
==00:00:00:07.941 18943== by 0xAD163CE: mysql_render_insert
(gda-mysql-provider.c:1565)
==00:00:00:07.941 18943== by 0xAD155DF:
gda_mysql_provider_statement_to_sql (gda-mysql-provider.c:1484)
==00:00:00:07.941 18943== by 0xAD1569F: real_prepare
(gda-mysql-provider.c:1826)
==00:00:00:07.941 18943== by 0xAD159DC:
gda_mysql_provider_statement_prepare (gda-mysql-provider.c:1917)
==00:00:00:07.941 18943== by 0xAD17386:
gda_mysql_provider_statement_execute (gda-mysql-provider.c:2208)
==00:00:00:07.941 18943== by 0x51705F8:
gda_connection_statement_execute_v (gda-connection.c:3544)
==00:00:00:07.941 18943== by 0x517200B: gda_connection_statement_execute
(gda-connection.c:3725)
==00:00:00:07.941 18943== by 0x54F8378: ast_db_record_new_full
(ast_db.c:652)
==00:00:00:07.941 18943== by 0x40095C: main (main.c:24)
Attached : Code sample
/*
* main.c
*
* Created on: Apr 4, 2014
* Author: memphis
*/
#include <glib.h>
#include <libgda/libgda.h>
#include <sql-parser/gda-sql-parser.h>
#include "ast_db.h"
GdaConnection* ast_db_get_connection() {
GError* error= NULL;
GdaConnection* result = NULL;
result = gda_connection_open_from_string("MySQL", "DB_NAME=ast", "USERNAME=root;PASSWORD=",GDA_CONNECTION_OPTIONS_NONE,&error);
if (result != NULL) {
GdaSqlParser* parserConnection = NULL;
//Create parser
parserConnection = gda_connection_create_parser (result);
if (!parserConnection) /* @cnc doe snot provide its own parser => use default one */
parserConnection = gda_sql_parser_new ();
/* attach the parser object to the connection */
g_object_set_data_full (G_OBJECT (result), "parser", parserConnection, g_object_unref);
} else {
g_critical("Ast:DB Failed to connect to the database. Error : %s", ast_error_get_error_message(error));
if (error != NULL)
g_error_free(error);
}
return result;
}
void ast_db_release(GdaConnection* connection) {
gpointer parser = g_object_steal_data(G_OBJECT(connection), "parser");
if (parser != NULL) g_object_unref(parser);
gda_connection_close(connection);
g_object_unref(connection);
}
GValue* ast_db_record_new_full(GdaConnection* dbConnection, const gchar* filename, gint size, guint64 startTime, guint64 endTime, gboolean isProtected, const gchar* timecode, gint sourceID) {
GValue* result = NULL;
GValue* filenameValue = gda_value_new_from_string(filename, G_TYPE_STRING);
GValue* sizeValue = gda_value_new(G_TYPE_INT);
g_value_set_int(sizeValue, size);
GValue* startTimeValue = gda_value_new(G_TYPE_UINT64);
g_value_set_uint64(startTimeValue, startTime);
GValue* endTimeValue = gda_value_new(G_TYPE_UINT64);
g_value_set_uint64(endTimeValue, endTime);
GValue* protectedValue = gda_value_new(G_TYPE_INT);
g_value_set_int(protectedValue, isProtected ? 1 : 0);
GValue* sourceIDValue = gda_value_new(G_TYPE_INT);
g_value_set_int(sourceIDValue, sourceID);
GValue* timecodeValue = gda_value_new_from_string(timecode, G_TYPE_STRING);
GdaStatement *stmt = NULL;
GdaSet * set = NULL;
GdaSet * lastRow = NULL;
GdaHolder *p = NULL;
GError * err = NULL;
GObject * res = NULL;
stmt = ast_db_common_get_statement(dbConnection, "INSERT INTO Records (filename, size, startTime, endTime, isProtected, timecode, fk_Sources ) VALUES ( ##the_filename::string , ##the_size::gint , ##the_startTime::guint64 , ##the_endTime::guint64 , ##the_protected::gint, ##the_timecode::string, ##the_sourceID::gint )");
if (stmt != NULL) {
gda_statement_get_parameters (stmt, &set, NULL);
p = gda_set_get_holder (set, "the_filename");
gda_holder_set_value (p, filenameValue, NULL);
p = gda_set_get_holder (set, "the_size");
gda_holder_set_value (p, sizeValue, NULL);
p = gda_set_get_holder (set, "the_startTime");
gda_holder_set_value (p, startTimeValue, NULL);
p = gda_set_get_holder (set, "the_endTime");
gda_holder_set_value (p, endTimeValue, NULL);
p = gda_set_get_holder (set, "the_protected");
gda_holder_set_value (p, protectedValue, NULL);
p = gda_set_get_holder (set, "the_timecode");
gda_holder_set_value (p, timecodeValue, NULL);
p = gda_set_get_holder (set, "the_sourceID");
gda_holder_set_value (p, sourceIDValue, NULL);
res = gda_connection_statement_execute(dbConnection,stmt, set,GDA_STATEMENT_MODEL_RANDOM_ACCESS, &lastRow, &err);
if (res != NULL) {
GdaHolder *h = GDA_HOLDER(lastRow->holders->data);
const GValue* holderValue = gda_holder_get_value(h);
result = gda_value_new(G_TYPE_INT);
g_value_set_int(result, g_value_get_int(holderValue));
g_object_unref(lastRow);
g_object_unref(res);
} else {
g_error ("Could not INSERT data into the 'Recorders' table: %s\n",
ast_error_get_error_message(err));
}
if (err != NULL)
g_error_free(err);
g_object_unref(stmt);
g_object_unref(set);
}
gda_value_free(filenameValue);
gda_value_free(sizeValue);
gda_value_free(startTimeValue);
gda_value_free(endTimeValue);
gda_value_free(protectedValue);
gda_value_free(sourceIDValue);
gda_value_free(timecodeValue);
return result;
}
int main(int argc, char* argv[]) {
g_type_init();
gint count = 0;
gint limit = 10;
gda_init();
while (count < limit) {
GdaConnection* connection = ast_db_get_connection();
GValue* id = ast_db_record_new_full(connection, "filename", 0, 0, 0, 0, "fddsfsdfdsffds", 7);
g_print(" ID : %d ", g_value_get_int(id));
gda_value_free(id);
ast_db_release(connection);
count++;
g_print("Count : %d\n", count);
}
return 0;
}
_______________________________________________
gnome-db-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/gnome-db-list