if (!i)
return NULL;
+ assert(i->n_ref > 0);
+ i->n_ref--;
+
+ if (i->n_ref > 0)
+ return NULL;
+
free(i->name);
free(i->path);
return mfree(i);
}
+Image *image_ref(Image *i) {
+ if (!i)
+ return NULL;
+
+ assert(i->n_ref > 0);
+ i->n_ref++;
+
+ return i;
+}
+
static char **image_settings_path(Image *image) {
_cleanup_strv_free_ char **l = NULL;
const char *fn, *s;
if (!i)
return -ENOMEM;
+ i->n_ref = 1;
i->type = t;
i->read_only = read_only;
i->crtime = crtime;
} ImageType;
typedef struct Image {
+ unsigned n_ref;
+
ImageType type;
char *name;
char *path;
} Image;
Image *image_unref(Image *i);
+Image *image_ref(Image *i);
+
static inline Hashmap* image_hashmap_free(Hashmap *map) {
return hashmap_free_with_destructor(map, image_unref);
}