machine-image: add proper refcounting

This commit is contained in:
Lennart Poettering
2018-05-24 17:01:57 +02:00
parent 2ddf182baa
commit 9614bb06ef
2 changed files with 21 additions and 0 deletions
+17
View File
@@ -61,6 +61,12 @@ Image *image_unref(Image *i) {
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);
@@ -71,6 +77,16 @@ Image *image_unref(Image *i) {
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;
@@ -131,6 +147,7 @@ static int image_new(
if (!i)
return -ENOMEM;
i->n_ref = 1;
i->type = t;
i->read_only = read_only;
i->crtime = crtime;