[gnome-bluetooth] Don't free the request_key and the passkey in agent reply functions



commit 7f8216b301aa2f740dbbd60cfbc4bb6abc0d629e
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Thu Nov 25 22:28:22 2010 +0100

    Don't free the request_key and the passkey in agent reply functions
    
    Even though those parameters were marked (transfer full), we were
    freeing the strings outside. Just remove the marking, sink functions
    are horrible to see.
    Also, we had the distinction between passkey and pincode reversed.
    "pincode" is a string, and "passkey" is numeric. Fix that.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=635023

 applet/agent.c            |    8 +++---
 applet/bluetooth-applet.c |   51 ++++++++++++++++++++------------------------
 applet/bluetooth-applet.h |    8 +++---
 3 files changed, 31 insertions(+), 36 deletions(-)
---
diff --git a/applet/agent.c b/applet/agent.c
index f56283a..24928e7 100644
--- a/applet/agent.c
+++ b/applet/agent.c
@@ -74,14 +74,14 @@ static void pin_callback(GtkWidget *dialog,
 
 		if (input->numeric == TRUE) {
 			guint pin = atoi(text);
-			bluetooth_applet_agent_reply_pincode (input->applet, input->path, pin);
+			bluetooth_applet_agent_reply_passkey (input->applet, input->path, pin);
 		} else
-			bluetooth_applet_agent_reply_passkey (input->applet, input->path, g_strdup (text));
+			bluetooth_applet_agent_reply_pincode (input->applet, input->path, text);
 	} else {
 		if (input->numeric == TRUE)
-			bluetooth_applet_agent_reply_pincode (input->applet, input->path, -1);
+			bluetooth_applet_agent_reply_passkey (input->applet, input->path, -1);
 		else
-			bluetooth_applet_agent_reply_passkey (input->applet, input->path, NULL);
+			bluetooth_applet_agent_reply_pincode (input->applet, input->path, NULL);
 	}
 
 	input_free(input);
diff --git a/applet/bluetooth-applet.c b/applet/bluetooth-applet.c
index b9d32ad..a9cb790 100644
--- a/applet/bluetooth-applet.c
+++ b/applet/bluetooth-applet.c
@@ -120,7 +120,7 @@ mount_ready_cb (GObject *object,
 		GAsyncResult *result,
 		gpointer user_data)
 {
-	GError *error;
+	GError *error = NULL;
 	GFile *file = G_FILE (object);
 	char *uri = g_file_get_uri (file);
 	MountClosure *closure = user_data;
@@ -259,16 +259,16 @@ void bluetooth_applet_send_to_address (BluetoothApplet *applet,
 }
 
 /**
- * bluetooth_applet_agent_reply_passkey:
+ * bluetooth_applet_agent_reply_pincode:
  *
  * @self: a #BluetoothApplet
- * @request_key: (transfer full): an opaque token given in the pincode-request signal
- * @passkey: (transfer full) (allow-none): the passkey entered by the user, or NULL if the dialog was dismissed
+ * @request_key: an opaque token given in the pincode-request signal
+ * @pincode: (allow-none): the PIN code entered by the user, as a string, or NULL if the dialog was dismissed
  */
 void
-bluetooth_applet_agent_reply_passkey (BluetoothApplet *self,
-				      char            *request_key,
-				      char            *passkey)
+bluetooth_applet_agent_reply_pincode (BluetoothApplet *self,
+				      const char      *request_key,
+				      const char      *pincode)
 {
 	DBusGMethodInvocation* context;
 
@@ -277,8 +277,8 @@ bluetooth_applet_agent_reply_passkey (BluetoothApplet *self,
 
 	context = g_hash_table_lookup (self->pending_requests, request_key);
 
-	if (passkey != NULL) {
-		dbus_g_method_return (context, passkey);
+	if (pincode != NULL) {
+		dbus_g_method_return (context, pincode);
 	} else {
 		GError *error;
 		error = g_error_new (AGENT_ERROR, AGENT_ERROR_REJECT,
@@ -287,21 +287,19 @@ bluetooth_applet_agent_reply_passkey (BluetoothApplet *self,
 	}
 
 	g_hash_table_remove (self->pending_requests, request_key);
-	g_free (request_key);
-	g_free (passkey);
 }
 
 /**
- * bluetooth_applet_agent_reply_pincode:
+ * bluetooth_applet_agent_reply_passkey:
  *
  * @self: a #BluetoothApplet
- * @request_key: (transfer full): an opaque token given in the pincode-request signal
- * @pincode: the PIN code entered by the user, or -1 if the dialog was dismissed
+ * @request_key: an opaque token given in the pincode-request signal
+ * @passkey: the numeric PIN code entered by the user, or -1 if the dialog was dismissed
  */
 void
-bluetooth_applet_agent_reply_pincode (BluetoothApplet *self,
-				      char            *request_key,
-				      int              pincode)
+bluetooth_applet_agent_reply_passkey (BluetoothApplet *self,
+				      const char      *request_key,
+				      int              passkey)
 {
 	DBusGMethodInvocation* context;
 
@@ -310,8 +308,8 @@ bluetooth_applet_agent_reply_pincode (BluetoothApplet *self,
 
 	context = g_hash_table_lookup (self->pending_requests, request_key);
 
-	if (pincode != -1) {
-		dbus_g_method_return (context, pincode);
+	if (passkey != -1) {
+		dbus_g_method_return (context, passkey);
 	} else {
 		GError *error;
 		error = g_error_new (AGENT_ERROR, AGENT_ERROR_REJECT,
@@ -320,19 +318,18 @@ bluetooth_applet_agent_reply_pincode (BluetoothApplet *self,
 	}
 
 	g_hash_table_remove (self->pending_requests, request_key);
-	g_free (request_key);
 }
 
 /**
  * bluetooth_applet_agent_reply_confirm:
  *
  * @self: a #BluetoothApplet
- * @request_key: (transfer full): an opaque token given in the pincode-request signal
+ * @request_key: an opaque token given in the pincode-request signal
  * @confirm: TRUE if operation was confirmed, FALSE otherwise
  */
 void
 bluetooth_applet_agent_reply_confirm (BluetoothApplet *self,
-				      char            *request_key,
+				      const char      *request_key,
 				      gboolean         confirm)
 {
 	DBusGMethodInvocation* context;
@@ -352,20 +349,19 @@ bluetooth_applet_agent_reply_confirm (BluetoothApplet *self,
 	}
 
 	g_hash_table_remove (self->pending_requests, request_key);
-	g_free (request_key);
 }
 
 /**
  * bluetooth_applet_agent_reply_auth:
  *
  * @self: a #BluetoothApplet
- * @request_key: (transfer full): an opaque token given in the pincode-request signal
+ * @request_key: an opaque token given in the pincode-request signal
  * @auth: TRUE if operation was authorized, FALSE otherwise
  * @trusted: TRUE if the operation should be authorized automatically in the future
  */
 void
 bluetooth_applet_agent_reply_auth (BluetoothApplet *self,
-				   char            *request_key,
+				   const char      *request_key,
 				   gboolean         auth,
 				   gboolean         trusted)
 {
@@ -389,7 +385,6 @@ bluetooth_applet_agent_reply_auth (BluetoothApplet *self,
 	}
 
 	g_hash_table_remove (self->pending_requests, request_key);
-	g_free (request_key);
 }
 
 #ifndef DBUS_TYPE_G_DICTIONARY
@@ -449,7 +444,7 @@ pincode_request (DBusGMethodInvocation *context,
 	path = dbus_g_proxy_get_path (device);
 	g_hash_table_insert (self->pending_requests, g_strdup (path), context);
 
-	g_signal_emit (self, signals[SIGNAL_PINCODE_REQUEST], 0, path, name, long_name, TRUE);
+	g_signal_emit (self, signals[SIGNAL_PINCODE_REQUEST], 0, path, name, long_name, FALSE);
 
 	g_free (name);
 	g_free (long_name);
@@ -471,7 +466,7 @@ passkey_request (DBusGMethodInvocation *context,
 	path = dbus_g_proxy_get_path (device);
 	g_hash_table_insert (self->pending_requests, g_strdup (path), context);
 
-	g_signal_emit (self, signals[SIGNAL_PINCODE_REQUEST], 0, path, name, long_name, FALSE);
+	g_signal_emit (self, signals[SIGNAL_PINCODE_REQUEST], 0, path, name, long_name, TRUE);
 
 	g_free (name);
 	g_free (long_name);
diff --git a/applet/bluetooth-applet.h b/applet/bluetooth-applet.h
index 26e8973..be10e08 100644
--- a/applet/bluetooth-applet.h
+++ b/applet/bluetooth-applet.h
@@ -131,9 +131,9 @@ void bluetooth_applet_send_to_address (BluetoothApplet *applet,
 
 gboolean bluetooth_applet_get_show_full_menu(BluetoothApplet* self);
 
-void bluetooth_applet_agent_reply_passkey(BluetoothApplet* self, gchar* request_key, gchar* passkey);
-void bluetooth_applet_agent_reply_pincode(BluetoothApplet* self, gchar* request_key, gint pincode);
-void bluetooth_applet_agent_reply_confirm(BluetoothApplet* self, gchar* request_key, gboolean confirm);
-void bluetooth_applet_agent_reply_auth(BluetoothApplet* self, gchar* request_key, gboolean auth, gboolean trusted);
+void bluetooth_applet_agent_reply_pincode(BluetoothApplet* self, const gchar* request_key, const gchar* pincode);
+void bluetooth_applet_agent_reply_passkey(BluetoothApplet* self, const gchar* request_key, gint passkey);
+void bluetooth_applet_agent_reply_confirm(BluetoothApplet* self, const gchar* request_key, gboolean confirm);
+void bluetooth_applet_agent_reply_auth(BluetoothApplet* self, const gchar* request_key, gboolean auth, gboolean trusted);
 
 #endif /* __BLUETOOTH_APPLET_H__ */



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