virThreadLocal chownList;
+static void
+virSecurityDACChownItemFree(virSecurityDACChownItem *item)
+{
+ if (!item)
+ return;
+
+ g_free(item->path);
+ g_free(item);
+}
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSecurityDACChownItem, virSecurityDACChownItemFree);
+
static int
virSecurityDACChownListAppend(virSecurityDACChownList *list,
const char *path,
bool remember,
bool restore)
{
- int ret = -1;
- char *tmp = NULL;
- virSecurityDACChownItem *item = NULL;
+ g_autoptr(virSecurityDACChownItem) item = NULL;
item = g_new0(virSecurityDACChownItem, 1);
- tmp = g_strdup(path);
-
- item->path = g_steal_pointer(&tmp);
+ item->path = g_strdup(path);
item->src = src;
item->uid = uid;
item->gid = gid;
item->restore = restore;
if (VIR_APPEND_ELEMENT(list->items, list->nItems, item) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- VIR_FREE(tmp);
- VIR_FREE(item);
- return ret;
+ return 0;
}
static void
if (!list)
return;
- for (i = 0; i < list->nItems; i++) {
- g_free(list->items[i]->path);
- g_free(list->items[i]);
- }
+ for (i = 0; i < list->nItems; i++)
+ virSecurityDACChownItemFree(list->items[i]);
g_free(list->items);
virObjectUnref(list->manager);
g_free(list);