Beispiel #1
0
/**
 * Finalizes the members of the DBusServer base class.
 * Chained up to by subclass finalizers.
 *
 * @param server the server.
 */
void
_dbus_server_finalize_base (DBusServer *server)
{
    /* We don't have the lock, but nobody should be accessing
     * concurrently since they don't have a ref
     */
#ifndef DBUS_DISABLE_CHECKS
    _dbus_assert (!server->have_server_lock);
#endif
    _dbus_assert (server->disconnected);

    /* calls out to application code... */
    _dbus_data_slot_list_free (&server->slot_list);

    dbus_server_set_new_connection_function (server, NULL, NULL, NULL);

    _dbus_watch_list_free (server->watches);
    _dbus_timeout_list_free (server->timeouts);

    _dbus_rmutex_free_at_location (&server->mutex);

    dbus_free (server->address);

    dbus_free_string_array (server->auth_mechanisms);

    _dbus_string_free (&server->guid_hex);
}
static void
_dbus_pending_call_last_unref (DBusPendingCall *pending)
{
  DBusConnection *connection;
  
  /* If we get here, we should be already detached
   * from the connection, or never attached.
   */
  _dbus_assert (!pending->timeout_added);  

  connection = pending->connection;

  /* this assumes we aren't holding connection lock... */
  _dbus_data_slot_list_free (&pending->slot_list);

  if (pending->timeout != NULL)
    _dbus_timeout_unref (pending->timeout);
      
  if (pending->timeout_link)
    {
      dbus_message_unref ((DBusMessage *)pending->timeout_link->data);
      _dbus_list_free_link (pending->timeout_link);
      pending->timeout_link = NULL;
    }

  if (pending->reply)
    {
      dbus_message_unref (pending->reply);
      pending->reply = NULL;
    }
      
  dbus_free (pending);

  dbus_pending_call_free_data_slot (&notify_user_data_slot);

  /* connection lock should not be held. */
  /* Free the connection last to avoid a weird state while
   * calling out to application code where the pending exists
   * but not the connection.
   */
  dbus_connection_unref (connection);
}
dbus_bool_t
_dbus_data_slot_test (void)
{
    DBusDataSlotAllocator allocator;
    DBusDataSlotList list;
    int i;
    DBusFreeFunction old_free_func;
    void *old_data;
    DBusMutex *mutex;

    if (!_dbus_data_slot_allocator_init (&allocator))
        _dbus_assert_not_reached ("no memory for allocator");

    _dbus_data_slot_list_init (&list);

    _dbus_mutex_new_at_location (&mutex);
    if (mutex == NULL)
        _dbus_assert_not_reached ("failed to alloc mutex");

#define N_SLOTS 100

    i = 0;
    while (i < N_SLOTS)
    {
        /* we don't really want apps to rely on this ordered
         * allocation, but it simplifies things to rely on it
         * here.
         */
        dbus_int32_t tmp = -1;

        _dbus_data_slot_allocator_alloc (&allocator, &mutex, &tmp);

        if (tmp != i)
            _dbus_assert_not_reached ("did not allocate slots in numeric order\n");

        ++i;
    }

    i = 0;
    while (i < N_SLOTS)
    {
        if (!_dbus_data_slot_list_set (&allocator, &list,
                                       i,
                                       _DBUS_INT_TO_POINTER (i),
                                       test_free_slot_data_func,
                                       &old_free_func, &old_data))
            _dbus_assert_not_reached ("no memory to set data");

        _dbus_assert (old_free_func == NULL);
        _dbus_assert (old_data == NULL);

        _dbus_assert (_dbus_data_slot_list_get (&allocator, &list, i) ==
                      _DBUS_INT_TO_POINTER (i));

        ++i;
    }

    free_counter = 0;
    i = 0;
    while (i < N_SLOTS)
    {
        if (!_dbus_data_slot_list_set (&allocator, &list,
                                       i,
                                       _DBUS_INT_TO_POINTER (i),
                                       test_free_slot_data_func,
                                       &old_free_func, &old_data))
            _dbus_assert_not_reached ("no memory to set data");

        _dbus_assert (old_free_func == test_free_slot_data_func);
        _dbus_assert (_DBUS_POINTER_TO_INT (old_data) == i);

        (* old_free_func) (old_data);
        _dbus_assert (i == (free_counter - 1));

        _dbus_assert (_dbus_data_slot_list_get (&allocator, &list, i) ==
                      _DBUS_INT_TO_POINTER (i));

        ++i;
    }

    free_counter = 0;
    _dbus_data_slot_list_free (&list);

    _dbus_assert (N_SLOTS == free_counter);

    i = 0;
    while (i < N_SLOTS)
    {
        dbus_int32_t tmp = i;

        _dbus_data_slot_allocator_free (&allocator, &tmp);
        _dbus_assert (tmp == -1);
        ++i;
    }

    _dbus_mutex_free_at_location (&mutex);

    return TRUE;
}