[libgda] GdaStatement: fix memory leak at statement execution
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] GdaStatement: fix memory leak at statement execution
- Date: Sat, 20 Apr 2019 00:18:16 +0000 (UTC)
commit 2bc8767b37f2fa17d6bdb29e16cc19b7863e1f29
Author: Daniel Espinosa <esodan gmail com>
Date: Fri Apr 19 15:05:41 2019 -0500
GdaStatement: fix memory leak at statement execution
libgda/gda-statement.c | 4 ++--
libgda/gda-util.c | 14 ++++++--------
libgda/sqlite/gda-sqlite-provider.c | 10 +++++-----
3 files changed, 13 insertions(+), 15 deletions(-)
---
diff --git a/libgda/gda-statement.c b/libgda/gda-statement.c
index 63d289138..40e8868c1 100644
--- a/libgda/gda-statement.c
+++ b/libgda/gda-statement.c
@@ -205,11 +205,11 @@ gda_statement_dispose (GObject *object)
stmt = GDA_STATEMENT (object);
GdaStatementPrivate *priv = gda_statement_get_instance_private (stmt);
- if (priv->requested_types) {
+ if (priv->requested_types != NULL) {
g_free (priv->requested_types);
priv->requested_types = NULL;
}
- if (priv->internal_struct) {
+ if (priv->internal_struct != NULL) {
gda_sql_statement_free (priv->internal_struct);
priv->internal_struct = NULL;
}
diff --git a/libgda/gda-util.c b/libgda/gda-util.c
index b22f96d24..436bb52b1 100644
--- a/libgda/gda-util.c
+++ b/libgda/gda-util.c
@@ -1628,7 +1628,8 @@ gda_rewrite_statement_for_null_parameters (GdaStatement *stmt, GdaSet *params,
GdaStatement **out_stmt, GError **error)
{
GdaSqlStatement *sqlst;
- gboolean mod;
+ gboolean mod = FALSE;
+ gboolean ret = FALSE;
g_return_val_if_fail (GDA_IS_STATEMENT (stmt), FALSE);
g_return_val_if_fail (!params || GDA_IS_SET (params), FALSE);
@@ -1642,16 +1643,13 @@ gda_rewrite_statement_for_null_parameters (GdaStatement *stmt, GdaSet *params,
if (out_stmt) {
if (mod) {
*out_stmt = g_object_new (GDA_TYPE_STATEMENT, "structure", sqlst, NULL);
- gda_sql_statement_free (sqlst);
+ ret = mod;
}
}
- return mod;
- }
- else {
- gda_sql_statement_free (sqlst);
- /* error => leave *out_stmt to %NULL */
- return TRUE;
}
+ gda_sql_statement_free (sqlst);
+ /* error => leave *out_stmt to %NULL */
+ return ret;
}
diff --git a/libgda/sqlite/gda-sqlite-provider.c b/libgda/sqlite/gda-sqlite-provider.c
index 7b3747b4b..6edf91e2d 100644
--- a/libgda/sqlite/gda-sqlite-provider.c
+++ b/libgda/sqlite/gda-sqlite-provider.c
@@ -3493,7 +3493,7 @@ gda_sqlite_provider_statement_execute (GdaServerProvider *provider, GdaConnectio
}
else if (gda_holder_value_is_default (h) && !gda_holder_get_value (h)) {
/* create a new GdaStatement to handle all default values and execute it instead */
- GdaSqlStatement *sqlst;
+ GdaSqlStatement *sqlst = NULL;
GError *lerror = NULL;
sqlst = gda_statement_rewrite_for_default_values (stmt, params, TRUE, &lerror);
if (!sqlst) {
@@ -3506,7 +3506,7 @@ gda_sqlite_provider_statement_execute (GdaServerProvider *provider, GdaConnectio
break;
}
- GdaStatement *rstmt;
+ GdaStatement *rstmt = NULL;
GObject *res;
rstmt = g_object_new (GDA_TYPE_STATEMENT, "structure", sqlst, NULL);
gda_sql_statement_free (sqlst);
@@ -3524,12 +3524,12 @@ gda_sqlite_provider_statement_execute (GdaServerProvider *provider, GdaConnectio
const GValue *value = gda_holder_get_value (h);
/*g_print ("BINDING param '%s' to GdaHolder %p, valued to [%s]\n", pname, h,
gda_value_stringify (value));*/
if (!value || gda_value_is_null (value)) {
- GdaStatement *rstmt;
+ GdaStatement *rstmt = NULL;
if (! gda_rewrite_statement_for_null_parameters (stmt, params, &rstmt, error))
SQLITE3_CALL (prov, sqlite3_bind_null) (_gda_sqlite_pstmt_get_stmt (ps), i);
- else if (!rstmt)
+ else if (rstmt == NULL) {
return NULL;
- else {
+ } else {
/* The strategy here is to execute @rstmt using its prepared
* statement, but with common data from @ps. Beware that
* the @param_ids attribute needs to be retained (i.e. it must not
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]