Commit 1027dfba authored by Pavlo Solntsev's avatar Pavlo Solntsev
Browse files

DB: Fixing memory leak and code optimization

parent ca22e988
Pipeline #224370 passed with stages
in 17 minutes and 8 seconds
......@@ -141,8 +141,7 @@ gda_db_base_set_names (GdaDbBase *self,
else
g_string_printf (fullnamestr, "%s", priv->m_name);
priv->m_fullname = g_strdup (fullnamestr->str);
g_string_free (fullnamestr, TRUE);
priv->m_fullname = g_string_free (fullnamestr, FALSE);
}
/**
......@@ -166,6 +165,7 @@ gda_db_base_get_full_name (GdaDbBase *self)
GdaDbBasePrivate *priv = gda_db_base_get_instance_private (self);
GString *fullnamestr = NULL;
g_free (priv->m_fullname);
fullnamestr = g_string_new (NULL);
......@@ -177,10 +177,12 @@ gda_db_base_get_full_name (GdaDbBase *self)
else if (priv->m_name)
g_string_printf (fullnamestr, "%s", priv->m_name);
else
{
g_string_free (fullnamestr, TRUE);
return NULL;
}
priv->m_fullname = g_strdup (fullnamestr->str);
g_string_free (fullnamestr, TRUE);
priv->m_fullname = g_string_free (fullnamestr, FALSE);
return priv->m_fullname;
}
......
......@@ -120,7 +120,7 @@ gda_db_catalog_dispose (GObject *object)
if (priv->cnc)
g_object_unref (priv->cnc);
G_OBJECT_CLASS (gda_db_catalog_parent_class)->finalize (object);
G_OBJECT_CLASS (gda_db_catalog_parent_class)->dispose (object);
}
static void
......@@ -220,10 +220,11 @@ _gda_db_catalog_get_dtd ()
if (g_file_test (file, G_FILE_TEST_EXISTS)) {
_gda_db_catalog_dtd = xmlParseDTD (NULL, (xmlChar*)file);
} else {
if (g_getenv ("GDA_TOP_SRC_DIR"))
const gchar *gdatopsrcdir = g_getenv ("GDA_TOP_SRC_DIR");
if (gdatopsrcdir)
{
g_free (file);
file = g_build_filename (g_getenv ("GDA_TOP_SRC_DIR"), "libgda",
file = g_build_filename (gdatopsrcdir, "libgda",
"libgda-db-catalog.dtd", NULL);
_gda_db_catalog_dtd = xmlParseDTD (NULL, (xmlChar*)file);
}
......@@ -638,9 +639,6 @@ _gda_db_table_new_from_meta (GdaMetaDbObject *obj)
if (!obj)
return gda_db_table_new ();
if (obj->obj_type != GDA_META_DB_TABLE)
return NULL;
GdaMetaTable *metatable = GDA_META_TABLE(obj);
GdaDbTable *table = gda_db_table_new ();
......@@ -655,9 +653,9 @@ _gda_db_table_new_from_meta (GdaMetaDbObject *obj)
GdaDbColumn *column = gda_db_column_new_from_meta (GDA_META_TABLE_COLUMN(it->data));
gda_db_table_append_column (table, column);
g_object_unref (column);
}
it = NULL;
for (it = metatable->fk_list;it;it = it->next)
{
if (!GDA_META_TABLE_FOREIGN_KEY_IS_DECLARED(GDA_META_TABLE_FOREIGN_KEY(it->data)))
......@@ -666,6 +664,7 @@ _gda_db_table_new_from_meta (GdaMetaDbObject *obj)
GdaDbFkey *fkey = gda_db_fkey_new_from_meta (GDA_META_TABLE_FOREIGN_KEY(it->data));
gda_db_table_append_fkey (table, fkey);
g_object_unref (fkey);
}
......@@ -749,10 +748,7 @@ gda_db_catalog_parse_cnc (GdaDbCatalog *self,
if(GDA_META_DB_OBJECT(it->data)->obj_type == GDA_META_DB_TABLE)
{
GdaDbTable *table = _gda_db_table_new_from_meta (it->data);
if (!table)
continue;
priv->mp_tables = g_list_append (priv->mp_tables,table);
priv->mp_tables = g_list_append (priv->mp_tables,table);
continue;
}
......
......@@ -178,6 +178,7 @@ gda_db_column_finalize (GObject *object)
g_free (priv->mp_type);
g_free (priv->mp_default);
g_free (priv->mp_check);
g_free (priv->mp_comment);
G_OBJECT_CLASS (gda_db_column_parent_class)->finalize (object);
}
......@@ -1127,13 +1128,10 @@ gda_db_column_prepare_create (GdaDbColumn *self,
g_free (numstr);
return FALSE;
}
else
{
g_free (numstr);
numstr = NULL;
}
}
g_free (numstr);
/* We need to set scale only for numeric column type */
if (priv->m_gtype == G_TYPE_FLOAT ||
priv->m_gtype == G_TYPE_DOUBLE ||
......@@ -1146,11 +1144,8 @@ gda_db_column_prepare_create (GdaDbColumn *self,
g_free (numstr);
return FALSE;
}
else
{
g_free (numstr);
numstr = NULL;
}
g_free (numstr);
}
if(!gda_server_operation_set_value_at (op, GDA_BOOL_TO_STR (priv->m_nnul), error,
......
......@@ -322,12 +322,15 @@ gda_db_table_parse_node (GdaDbBuildable *buildable,
name = xmlGetProp (node, (xmlChar *)gdadbtablenodes[GDA_DB_TABLE_NAME]);
g_assert (name); /* If here bug with xml validation */
gda_db_base_set_name(GDA_DB_BASE(self), (gchar*)name);
xmlFree(name);
xmlChar *tempt = xmlGetProp (node, (xmlChar*)gdadbtablenodes[GDA_DB_TABLE_TEMP]);
if (tempt && (*tempt == 't' || *tempt == 't'))
if (tempt)
{
g_object_set (G_OBJECT(self), "istemp", TRUE, NULL);
if (*tempt == 't' || *tempt == 't')
g_object_set (G_OBJECT(self), "istemp", TRUE, NULL);
xmlFree (tempt);
}
......
......@@ -1771,7 +1771,7 @@ create_view_object (GdaMetaStorePrivate *priv, GdaMetaStore *store, xmlNodePtr n
if (!view_name) {
g_set_error (error, GDA_META_STORE_ERROR, GDA_META_STORE_META_CONTEXT_ERROR,
"%s", _("Missing view name from <view> node"));
goto onerror;
return NULL;
}
/* determine object's complete name */
......
......@@ -98,7 +98,9 @@ test1a (void)
provs = gda_config_list_providers ();
g_assert (provs != NULL);
g_assert (gda_data_model_get_n_rows (provs) >= 1);
g_print ("Providers:\n%s\n", gda_data_model_dump_as_string (provs));
gchar *printstr = gda_data_model_dump_as_string (provs);
g_print ("Providers:\n%s\n", printstr);
g_free (printstr);
sqlite = gda_config_get_provider ("SQLite", &error);
if (error != NULL) {
......
......@@ -105,7 +105,9 @@ test_db_catalog_start (CheckDbObject *self,
g_assert_nonnull (self->catalog);
self->file = g_file_new_for_path (self->xmlfile);
g_print ("GFile is %s\n",g_file_get_path(self->file));
gchar *strpath = g_file_get_path (self->file);
g_print ("GFile is %s\n", strpath);
g_free (strpath);
}
static void
......@@ -146,6 +148,7 @@ test_db_catalog_start_db (DbCatalogCnc *self,
gda_db_column_set_pkey (self->column_id, TRUE);
gda_db_table_append_column (self->table,self->column_id);
g_object_unref (self->column_id);
self->column_name = gda_db_column_new ();
gda_db_column_set_name (self->column_name,"name");
......@@ -153,30 +156,37 @@ test_db_catalog_start_db (DbCatalogCnc *self,
gda_db_column_set_size (self->column_name, 50);
gda_db_table_append_column (self->table,self->column_name);
g_object_unref (self->column_name);
self->column_ctime = gda_db_column_new ();
gda_db_column_set_name (self->column_ctime,"create_time");
gda_db_column_set_type (self->column_ctime, GDA_TYPE_TIME);
gda_db_table_append_column (self->table,self->column_ctime);
g_object_unref (self->column_ctime);
self->column_state = gda_db_column_new ();
gda_db_column_set_name (self->column_state,"state");
gda_db_column_set_type (self->column_state, G_TYPE_BOOLEAN);
gda_db_table_append_column (self->table,self->column_state);
g_object_unref (self->column_state);
self->column_ts = gda_db_column_new ();
gda_db_column_set_name (self->column_ts,"mytimestamp");
gda_db_column_set_type (self->column_ts, G_TYPE_DATE_TIME);
gda_db_table_append_column (self->table,self->column_ts);
g_object_unref (self->column_ts);
gda_db_catalog_append_table (self->catalog, self->table);
g_object_unref (self->table);
open_res = gda_db_catalog_perform_operation (self->catalog,NULL);
g_assert_true (open_res);
g_object_unref (self->catalog);
}
static void
......@@ -194,14 +204,7 @@ static void
test_db_catalog_finish_db (DbCatalogCnc *self,
G_GNUC_UNUSED gconstpointer user_data)
{
gda_connection_close(self->cnc,NULL);
g_object_unref (self->cnc);
g_object_unref (self->catalog);
g_object_unref (self->column_id);
g_object_unref (self->column_name);
g_object_unref (self->column_ctime);
g_object_unref (self->column_ts);
g_object_unref (self->table);
}
static void
......@@ -455,6 +458,7 @@ test_db_catalog_constraint_start (DbCheckCatallog *self,
gda_db_column_set_pkey (self->column_a, TRUE);
gda_db_table_append_column (self->table,self->column_a);
g_object_unref (self->column_a);
self->column_b = gda_db_column_new ();
gda_db_column_set_name (self->column_b, "columnb");
......@@ -463,14 +467,18 @@ test_db_catalog_constraint_start (DbCheckCatallog *self,
gda_db_column_set_pkey (self->column_b, FALSE);
gda_db_table_append_column (self->table, self->column_b);
g_object_unref (self->column_b);
gda_db_table_append_constraint (self->table, "CHECK (columna = columnb)");
gda_db_catalog_append_table (self->catalog, self->table);
g_object_unref (self->table);
open_res = gda_db_catalog_perform_operation (self->catalog,NULL);
g_assert_true (open_res);
g_object_unref (self->catalog);
}
static void
......@@ -527,7 +535,6 @@ static void
test_db_catalog_constraint_finish (DbCheckCatallog *self,
G_GNUC_UNUSED gconstpointer user_data)
{
g_object_unref (self->catalog);
gda_connection_close (self->cnc, NULL);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment