goto failed;
}
- _dbus_list_foreach (&activation->directories,
- (DBusForeachFunction) bus_service_directory_unref, NULL);
- _dbus_list_clear (&activation->directories);
+ _dbus_list_clear_full (&activation->directories,
+ (DBusFreeFunction) bus_service_directory_unref);
link = _dbus_list_get_first_link (directories);
while (link != NULL)
if (activation->pending_activations)
_dbus_hash_table_unref (activation->pending_activations);
- _dbus_list_foreach (&activation->directories,
- (DBusForeachFunction) bus_service_directory_unref, NULL);
- _dbus_list_clear (&activation->directories);
+ _dbus_list_clear_full (&activation->directories,
+ (DBusFreeFunction) bus_service_directory_unref);
if (activation->environment)
_dbus_hash_table_unref (activation->environment);
_dbus_string_free (&parser->user);
_dbus_string_free (&parser->service_helper);
_dbus_string_free (&parser->bus_type);
-
- _dbus_list_foreach (&parser->service_dirs,
- (DBusForeachFunction) dbus_free,
- NULL);
-
- _dbus_list_clear (&parser->service_dirs);
-
+ _dbus_list_clear_full (&parser->service_dirs, dbus_free);
dbus_free (parser);
}
dbus_free (parser->servicehelper);
dbus_free (parser->bus_type);
dbus_free (parser->pidfile);
-
- _dbus_list_foreach (&parser->listen_on,
- (DBusForeachFunction) dbus_free,
- NULL);
-
- _dbus_list_clear (&parser->listen_on);
-
- _dbus_list_foreach (&parser->service_dirs,
- (DBusForeachFunction) bus_config_service_dir_free,
- NULL);
-
- _dbus_list_clear (&parser->service_dirs);
- _dbus_list_foreach (&parser->conf_dirs,
- (DBusForeachFunction) dbus_free,
- NULL);
+ _dbus_list_clear_full (&parser->listen_on, dbus_free);
+ _dbus_list_clear_full (&parser->service_dirs,
+ (DBusFreeFunction) bus_config_service_dir_free);
+ _dbus_list_clear_full (&parser->conf_dirs, dbus_free);
+ _dbus_list_clear_full (&parser->mechanisms, dbus_free);
- _dbus_list_clear (&parser->conf_dirs);
-
- _dbus_list_foreach (&parser->mechanisms,
- (DBusForeachFunction) dbus_free,
- NULL);
-
- _dbus_list_clear (&parser->mechanisms);
-
_dbus_string_free (&parser->basedir);
if (parser->policy)
BUS_SERVICE_DIR_FLAGS_STRICT_NAMING))
{
BUS_SET_OOM (error);
- _dbus_list_foreach (&dirs, (DBusForeachFunction) dbus_free,
- NULL);
- _dbus_list_clear (&dirs);
+ _dbus_list_clear_full (&dirs, dbus_free);
return FALSE;
}
}
BUS_SERVICE_DIR_FLAGS_NONE))
{
BUS_SET_OOM (error);
- _dbus_list_foreach (&dirs, (DBusForeachFunction) dbus_free,
- NULL);
- _dbus_list_clear (&dirs);
+ _dbus_list_clear_full (&dirs, dbus_free);
return FALSE;
}
BUS_SERVICE_DIR_FLAGS_NONE))
{
BUS_SET_OOM (error);
- _dbus_list_foreach (&dirs, (DBusForeachFunction) dbus_free,
- NULL);
- _dbus_list_clear (&dirs);
+ _dbus_list_clear_full (&dirs, dbus_free);
return FALSE;
}
_dbus_hash_table_unref (connection->pending_replies);
connection->pending_replies = NULL;
-
+
_dbus_list_foreach (&connection->outgoing_messages,
free_outgoing_message,
connection);
_dbus_list_clear (&connection->outgoing_messages);
-
- _dbus_list_foreach (&connection->incoming_messages,
- (DBusForeachFunction) dbus_message_unref,
- NULL);
- _dbus_list_clear (&connection->incoming_messages);
+
+ _dbus_list_clear_full (&connection->incoming_messages,
+ (DBusFreeFunction) dbus_message_unref);
_dbus_counter_unref (connection->outgoing_counter);
link = next;
}
- _dbus_list_foreach (&filter_list_copy,
- (DBusForeachFunction)_dbus_message_filter_unref,
- NULL);
- _dbus_list_clear (&filter_list_copy);
-
+ _dbus_list_clear_full (&filter_list_copy,
+ (DBusFreeFunction) _dbus_message_filter_unref);
+
CONNECTION_LOCK (connection);
if (result == DBUS_HANDLER_RESULT_NEED_MEMORY)
*list = NULL;
}
+/**
+ * Free every link and every element in the list.
+ *
+ * @param list address of the head of the list.
+ * @param function free-function to call for each element.
+ *
+ */
+void
+_dbus_list_clear_full (DBusList **list,
+ DBusFreeFunction function)
+{
+ DBusList *link;
+
+ link = *list;
+ while (link != NULL)
+ {
+ DBusList *next = _dbus_list_get_next_link (list, link);
+
+ function (link->data);
+ free_link (link);
+
+ link = next;
+ }
+
+ *list = NULL;
+}
+
/**
* Gets the first link in the list.
* This is a constant-time operation.
DBUS_PRIVATE_EXPORT
void _dbus_list_clear (DBusList **list);
DBUS_PRIVATE_EXPORT
+void _dbus_list_clear_full (DBusList **list,
+ DBusFreeFunction function);
+DBUS_PRIVATE_EXPORT
DBusList* _dbus_list_get_first_link (DBusList **list);
DBUS_PRIVATE_EXPORT
DBusList* _dbus_list_get_last_link (DBusList **list);
close_unix_fds(loader->unix_fds, &loader->n_unix_fds);
dbus_free(loader->unix_fds);
#endif
- _dbus_list_foreach (&loader->messages,
- (DBusForeachFunction) dbus_message_unref,
- NULL);
- _dbus_list_clear (&loader->messages);
+ _dbus_list_clear_full (&loader->messages,
+ (DBusFreeFunction) dbus_message_unref);
_dbus_string_free (&loader->data);
dbus_free (loader);
}
_dbus_string_free (¤t_token);
init_error:
- if (retval)
- {
- _dbus_list_foreach (&retval, (DBusForeachFunction) dbus_free, NULL);
- _dbus_list_clear (&retval);
- }
-
+ _dbus_list_clear_full (&retval, dbus_free);
return NULL;
}
++i;
}
argv[argc] = NULL;
-
- _dbus_list_foreach (&tokens, (DBusForeachFunction) dbus_free, NULL);
- _dbus_list_clear (&tokens);
+
+ _dbus_list_clear_full (&tokens, dbus_free);
if (argcp)
*argcp = argc;
return TRUE;
error:
- _dbus_list_foreach (&tokens, (DBusForeachFunction) dbus_free, NULL);
- _dbus_list_clear (&tokens);
+ _dbus_list_clear_full (&tokens, dbus_free);
return FALSE;
return TRUE;
oom:
- _dbus_list_foreach (dir_list, (DBusForeachFunction)dbus_free, NULL);
- _dbus_list_clear (dir_list);
+ _dbus_list_clear_full (dir_list, dbus_free);
return FALSE;
}
_dbus_timeout_list_set_functions (timeout_list,
NULL, NULL, NULL, NULL, NULL);
- _dbus_list_foreach (&timeout_list->timeouts,
- (DBusForeachFunction) _dbus_timeout_unref,
- NULL);
- _dbus_list_clear (&timeout_list->timeouts);
+ _dbus_list_clear_full (&timeout_list->timeouts,
+ (DBusFreeFunction) _dbus_timeout_unref);
dbus_free (timeout_list);
}
/* free watch_data and removes watches as a side effect */
_dbus_watch_list_set_functions (watch_list,
NULL, NULL, NULL, NULL, NULL);
- _dbus_list_foreach (&watch_list->watches,
- (DBusForeachFunction) _dbus_watch_unref,
- NULL);
- _dbus_list_clear (&watch_list->watches);
+
+ _dbus_list_clear_full (&watch_list->watches,
+ (DBusFreeFunction) _dbus_watch_unref);
dbus_free (watch_list);
}