[libgda] gda-vprovider: improved internal free resources



commit 93608a8095e80e00a74bfaebe9f32a60c69f3489
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Sep 26 16:23:41 2018 -0500

    gda-vprovider: improved internal free resources

 libgda/sqlite/virtual/gda-vconnection-data-model.c | 9 +++------
 libgda/sqlite/virtual/gda-vprovider-data-model.c   | 6 +++++-
 2 files changed, 8 insertions(+), 7 deletions(-)
---
diff --git a/libgda/sqlite/virtual/gda-vconnection-data-model.c 
b/libgda/sqlite/virtual/gda-vconnection-data-model.c
index 8b3d5b33b..3bc80d3e1 100644
--- a/libgda/sqlite/virtual/gda-vconnection-data-model.c
+++ b/libgda/sqlite/virtual/gda-vconnection-data-model.c
@@ -3,6 +3,7 @@
  * Copyright (C) 2008 - 2011 Murray Cumming <murrayc murrayc com>
  * Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
  * Copyright (C) 2010 David King <davidk openismus com>
+ * Copyright (C) 2018 Daniel Espinosa <esodan gmail com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -618,13 +619,8 @@ vcontext_free (VContext *context)
                g_object_weak_unref (context->context_object,
                                     (GWeakNotify) vcontext_object_weak_notify_cb, context);
        if (context->context_data) {
-               guint i;
-               for (i = 0; i < context->context_data->len; i++) {
-                       VirtualFilteredData *data;
-                       data = g_array_index (context->context_data, VirtualFilteredData*, i);
-                       _gda_vconnection_virtual_filtered_data_unref (data);
-               }
                g_array_free (context->context_data, TRUE);
+               context->context_data = NULL;
        }
        g_free (context);
 #ifdef DEBUG_VCONTEXT
@@ -655,6 +651,7 @@ _gda_vconnection_set_working_obj (GdaVconnectionDataModel *cnc, GObject *obj)
                                vc->context_object = obj;
                                vc->context_data = g_array_new (FALSE, FALSE,
                                                                sizeof (VirtualFilteredData*));
+                               g_array_set_clear_func (vc->context_data, (GDestroyNotify) 
_gda_vconnection_virtual_filtered_data_unref);
                                vc->vtable = td;
                                g_object_weak_ref (obj, (GWeakNotify) vcontext_object_weak_notify_cb, vc);
                                g_hash_table_insert (td->context.hash, obj, vc);
diff --git a/libgda/sqlite/virtual/gda-vprovider-data-model.c 
b/libgda/sqlite/virtual/gda-vprovider-data-model.c
index 65e39745e..c201fc21f 100644
--- a/libgda/sqlite/virtual/gda-vprovider-data-model.c
+++ b/libgda/sqlite/virtual/gda-vprovider-data-model.c
@@ -2,7 +2,7 @@
  * Copyright (C) 2007 - 2016 Vivien Malerba <malerba gnome-db org>
  * Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
  * Copyright (C) 2010 David King <davidk openismus com>
- * Copyright (C) 2017 Daniel Espinosa <esodan gmail com>
+ * Copyright (C) 2017,2018 Daniel Espinosa <esodan gmail com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -277,6 +277,7 @@ virtual_filtered_data_new (VirtualTable *vtable, GdaDataModel *model,
 static void
 virtual_filtered_data_free (VirtualFilteredData *data)
 {
+       g_return_if_fail (data != NULL);
        if (data->argv) {
                int i;
                for (i = 0; i < data->argc; i++)
@@ -307,6 +308,7 @@ virtual_filtered_data_free (VirtualFilteredData *data)
 static VirtualFilteredData *
 virtual_filtered_data_ref (VirtualFilteredData *data)
 {
+       g_return_if_fail (data != NULL);
        data->refcount ++;
        return data;
 }
@@ -314,6 +316,7 @@ virtual_filtered_data_ref (VirtualFilteredData *data)
 void
 _gda_vconnection_virtual_filtered_data_unref (VirtualFilteredData *data)
 {
+       g_return_if_fail (data != NULL);
        data->refcount --;
        if (data->refcount == 0)
                virtual_filtered_data_free (data);
@@ -326,6 +329,7 @@ virtual_cursor_free (VirtualCursor *cursor)
                return;
 
        _gda_vconnection_virtual_filtered_data_unref (cursor->data);
+       cursor->data = NULL;
        g_free (cursor);
 }
 


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