[tracker/wip/carlosg/leak-fixes: 4/4] libtracker-sparql: Plug GError leak in TrackerEndpointDBus



commit 955efb0299fd1ce014e71f2b77d6d4ca663a02c2
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Jun 6 15:17:14 2020 +0200

    libtracker-sparql: Plug GError leak in TrackerEndpointDBus
    
    The error handling in handle_cursor_reply() is somewhat iffy, on
    one hand it "takes" an error without freeing it, and on the other
    hand it can reuse the error variable for the handling of inner
    errors.
    
    Make the error argument const (and freed outside the handle_cursor_reply
    call) and use a separate GError for the inner write_cursor() handling.

 src/libtracker-sparql/tracker-endpoint-dbus.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-sparql/tracker-endpoint-dbus.c b/src/libtracker-sparql/tracker-endpoint-dbus.c
index 0fec72cbf..d874b8028 100644
--- a/src/libtracker-sparql/tracker-endpoint-dbus.c
+++ b/src/libtracker-sparql/tracker-endpoint-dbus.c
@@ -266,9 +266,10 @@ write_cursor (QueryRequest          *request,
 static void
 handle_cursor_reply (QueryRequest        *request,
                      TrackerSparqlCursor *cursor,
-                     GError              *error)
+                     const GError        *error)
 {
        const gchar **variable_names = NULL;
+       GError *write_error = NULL;
        gint i, n_columns;
 
        if (!error) {
@@ -277,16 +278,19 @@ handle_cursor_reply (QueryRequest        *request,
                for (i = 0; i < n_columns; i++)
                        variable_names[i] = tracker_sparql_cursor_get_variable_name (cursor, i);
 
-               write_cursor (request, cursor, &error);
+               write_cursor (request, cursor, &write_error);
        }
 
        if (error)
                g_dbus_method_invocation_return_gerror (request->invocation, error);
+       else if (write_error)
+               g_dbus_method_invocation_return_gerror (request->invocation, write_error);
        else
                g_dbus_method_invocation_return_value (request->invocation, g_variant_new ("(^as)", 
variable_names));
 
        g_free (variable_names);
        g_clear_object (&cursor);
+       g_clear_error (&write_error);
 }
 
 static void
@@ -302,6 +306,7 @@ query_cb (GObject      *object,
                                                         res, &error);
        handle_cursor_reply (request, cursor, error);
        query_request_free (request);
+       g_clear_error (&error);
 }
 
 static void
@@ -317,6 +322,7 @@ stmt_execute_cb (GObject      *object,
                                                          res, &error);
        handle_cursor_reply (request, cursor, error);
        query_request_free (request);
+       g_clear_error (&error);
 }
 
 static void


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