summaryrefslogtreecommitdiff
path: root/dbus/dbus-auth.c
diff options
context:
space:
mode:
authorCosimo Alfarano <cosimo.alfarano@collabora.com>2013-08-23 02:12:46 +0200
committerRalf Habacker <ralf.habacker@freenet.de>2013-08-23 02:14:28 +0200
commit7f6d7229d8812d985d544cf5dd3636865c5abc81 (patch)
treeb3b5bd0f7440ce72a0befdce0109618b8ce527b5 /dbus/dbus-auth.c
parent22fc03d274f186a788efbdbe6b6dfcff1ad474df (diff)
downloaddbus-7f6d7229d8812d985d544cf5dd3636865c5abc81.tar.gz
Remove refcounting from DBusAuth and DBusAuthorization
Those structs are for DBusTransport internal use, they should not be referenced outside it. The transport needs only to allocate memory on initialization and free it on finalization. The lifecycle for the two allocated structs is DBusTransport lifecycle and at DBusTransport's finalization its connection is already disconnected. The assumption is that the transport owns a reference for any object the two structs holds a reference for (particularly DBusConnection) Bug: http://bugs.freedesktop.org/show_bug.cgi?id=39720 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Diffstat (limited to 'dbus/dbus-auth.c')
-rw-r--r--dbus/dbus-auth.c81
1 files changed, 28 insertions, 53 deletions
diff --git a/dbus/dbus-auth.c b/dbus/dbus-auth.c
index a2187016..3da25ec5 100644
--- a/dbus/dbus-auth.c
+++ b/dbus/dbus-auth.c
@@ -153,7 +153,6 @@ typedef struct
*/
struct DBusAuth
{
- int refcount; /**< reference count */
const char *side; /**< Client or server */
DBusString incoming; /**< Incoming data buffer */
@@ -346,8 +345,6 @@ _dbus_auth_new (int size)
if (auth == NULL)
return NULL;
- auth->refcount = 1;
-
auth->keyring = NULL;
auth->cookie_id = -1;
@@ -2262,7 +2259,7 @@ process_command (DBusAuth *auth)
*/
DBusAuth*
_dbus_auth_server_new (const DBusString *guid,
- DBusAuthorization *authorization)
+ DBusAuthorization *authorization)
{
DBusAuth *auth;
DBusAuthServer *server_auth;
@@ -2290,7 +2287,7 @@ _dbus_auth_server_new (const DBusString *guid,
server_auth = DBUS_AUTH_SERVER (auth);
server_auth->guid = guid_copy;
- server_auth->authorization = _dbus_authorization_ref (authorization);
+ server_auth->authorization = authorization;
/* perhaps this should be per-mechanism with a lower
* max
@@ -2333,7 +2330,7 @@ _dbus_auth_client_new (void)
* mechanism */
if (!send_auth (auth, &all_mechanisms[0]))
{
- _dbus_auth_unref (auth);
+ _dbus_auth_free (auth);
return NULL;
}
@@ -2341,67 +2338,45 @@ _dbus_auth_client_new (void)
}
/**
- * Increments the refcount of an auth object.
- *
- * @param auth the auth conversation
- * @returns the auth conversation
- */
-DBusAuth *
-_dbus_auth_ref (DBusAuth *auth)
-{
- _dbus_assert (auth != NULL);
-
- auth->refcount += 1;
-
- return auth;
-}
-
-/**
- * Decrements the refcount of an auth object.
+ * Free memory allocated for an auth object.
*
* @param auth the auth conversation
*/
void
-_dbus_auth_unref (DBusAuth *auth)
+_dbus_auth_free (DBusAuth *auth)
{
_dbus_assert (auth != NULL);
- _dbus_assert (auth->refcount > 0);
- auth->refcount -= 1;
- if (auth->refcount == 0)
+ shutdown_mech (auth);
+
+ if (DBUS_AUTH_IS_CLIENT (auth))
{
- shutdown_mech (auth);
+ _dbus_string_free (& DBUS_AUTH_CLIENT (auth)->guid_from_server);
+ _dbus_list_clear (& DBUS_AUTH_CLIENT (auth)->mechs_to_try);
+ }
+ else
+ {
+ _dbus_assert (DBUS_AUTH_IS_SERVER (auth));
- if (DBUS_AUTH_IS_CLIENT (auth))
- {
- _dbus_string_free (& DBUS_AUTH_CLIENT (auth)->guid_from_server);
- _dbus_list_clear (& DBUS_AUTH_CLIENT (auth)->mechs_to_try);
- }
- else
- {
- _dbus_assert (DBUS_AUTH_IS_SERVER (auth));
+ _dbus_string_free (& DBUS_AUTH_SERVER (auth)->guid);
+ }
- _dbus_string_free (& DBUS_AUTH_SERVER (auth)->guid);
- _dbus_authorization_unref (DBUS_AUTH_SERVER (auth)->authorization);
- }
+ if (auth->keyring)
+ _dbus_keyring_unref (auth->keyring);
- if (auth->keyring)
- _dbus_keyring_unref (auth->keyring);
+ _dbus_string_free (&auth->context);
+ _dbus_string_free (&auth->challenge);
+ _dbus_string_free (&auth->identity);
+ _dbus_string_free (&auth->incoming);
+ _dbus_string_free (&auth->outgoing);
- _dbus_string_free (&auth->context);
- _dbus_string_free (&auth->challenge);
- _dbus_string_free (&auth->identity);
- _dbus_string_free (&auth->incoming);
- _dbus_string_free (&auth->outgoing);
+ dbus_free_string_array (auth->allowed_mechs);
- dbus_free_string_array (auth->allowed_mechs);
+ _dbus_credentials_unref (auth->credentials);
+ _dbus_credentials_unref (auth->authenticated_identity);
+ _dbus_credentials_unref (auth->desired_identity);
- _dbus_credentials_unref (auth->credentials);
- _dbus_credentials_unref (auth->authenticated_identity);
- _dbus_credentials_unref (auth->desired_identity);
-
- dbus_free (auth);
- }
+ dbus_free (auth);
}
/**