[libgda] GdaMetaStore: avoid static variable for attributes
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] GdaMetaStore: avoid static variable for attributes
- Date: Tue, 20 Aug 2019 13:57:17 +0000 (UTC)
commit 806a0b3c2099ebd1eed71a33c7a156f0f364fd25
Author: Daniel Espinosa <esodan gmail com>
Date: Fri Aug 2 11:56:05 2019 -0500
GdaMetaStore: avoid static variable for attributes
static variables are potential memory leaks and are
hard to coordinate on mutil-threaded environments
libgda/gda-meta-store.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
---
diff --git a/libgda/gda-meta-store.c b/libgda/gda-meta-store.c
index d0ecb49e0..86aa0451e 100644
--- a/libgda/gda-meta-store.c
+++ b/libgda/gda-meta-store.c
@@ -657,6 +657,7 @@ typedef struct {
* the parameters separated by a period,
* value = a TableConditionInfo structure */
GHashTable *provider_specifics; /* key = a ProviderSpecificKey , value = a ProviderSpecificValue */
+ GdaSet *attributes_set;
} GdaMetaStorePrivate;
@@ -899,7 +900,7 @@ gda_meta_store_init (GdaMetaStore *store)
priv->prep_stmts[STMT_DEL_DECLARE_FK] =
compute_prepared_stmt (priv->parser,
"DELETE FROM __declared_fk WHERE constraint_name = ##fkname::string
AND table_catalog = ##tcal::string AND table_schema = ##tschema::string AND table_name = ##tname::string AND
ref_table_catalog = ##ref_tcal::string AND ref_table_schema = ##ref_tschema::string AND ref_table_name =
##ref_tname::string");
-
+ priv->attributes_set = NULL;
/*#define GDA_DEBUG_GRAPH*/
#ifdef GDA_DEBUG_GRAPH
#define INFORMATION_SCHEMA_GRAPH_FILE "information_schema.dot"
@@ -1154,6 +1155,10 @@ gda_meta_store_dispose (GObject *object)
g_free (priv->prep_stmts);
priv->prep_stmts = NULL;
}
+ if (priv->attributes_set != NULL) {
+ g_object_unref (priv->attributes_set);
+ priv->attributes_set = NULL;
+ }
g_rec_mutex_clear (& (priv->mutex));
@@ -4371,8 +4376,6 @@ gboolean
gda_meta_store_set_attribute_value (GdaMetaStore *store, const gchar *att_name,
const gchar *att_value, GError **error)
{
- static GMutex set_mutex;
- static GdaSet *set = NULL;
gboolean started_transaction = FALSE;
g_return_val_if_fail (GDA_IS_META_STORE (store), FALSE);
@@ -4387,17 +4390,14 @@ gda_meta_store_set_attribute_value (GdaMetaStore *store, const gchar *att_name,
g_rec_mutex_lock (& (priv->mutex));
- g_mutex_lock (&set_mutex);
- if (!set) {
- if (!gda_statement_get_parameters (priv->prep_stmts [STMT_SET_ATT_VALUE], &set, error)) {
- g_mutex_unlock (&set_mutex);
+ if (!priv->attributes_set) {
+ if (!gda_statement_get_parameters (priv->prep_stmts [STMT_SET_ATT_VALUE],
&priv->attributes_set, error)) {
g_rec_mutex_unlock (& (priv->mutex));
return FALSE;
}
}
- g_mutex_unlock (&set_mutex);
- if (!gda_set_set_holder_value (set, error, "name", att_name)) {
+ if (!gda_set_set_holder_value (priv->attributes_set, error, "name", att_name)) {
g_rec_mutex_unlock (& (priv->mutex));
return FALSE;
}
@@ -4415,17 +4415,17 @@ gda_meta_store_set_attribute_value (GdaMetaStore *store, const gchar *att_name,
/* delete existing attribute */
if (gda_connection_statement_execute_non_select (priv->cnc,
- priv->prep_stmts [STMT_DEL_ATT_VALUE], set,
+ priv->prep_stmts [STMT_DEL_ATT_VALUE],
priv->attributes_set,
NULL, error) == -1)
goto onerror;
if (att_value) {
/* set new attribute */
- if (!gda_set_set_holder_value (set, error, "value", att_value))
+ if (!gda_set_set_holder_value (priv->attributes_set, error, "value", att_value))
goto onerror;
if (gda_connection_statement_execute_non_select (priv->cnc,
- priv->prep_stmts [STMT_SET_ATT_VALUE], set,
+ priv->prep_stmts [STMT_SET_ATT_VALUE],
priv->attributes_set,
NULL, error) == -1)
goto onerror;
}
@@ -5455,3 +5455,4 @@ gda_meta_store_create_struct (GdaMetaStore *store, GdaMetaStructFeature features
{
return (GdaMetaStruct*) g_object_new (GDA_TYPE_META_STRUCT, "meta-store", store, "features", features,
NULL);
}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]