Debian Codegraph @

src/sysupdate/sysupdate-instance.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "alloc-util.h"
4 #include "log.h"
5 #include "sysupdate-instance.h"
6
7 void instance_metadata_destroy(InstanceMetadata *m) {
8 assert(m);
9 free(m->version);
10 }
11
12 int instance_new(
13 Resource *rr,
14 const char *path,
15 const InstanceMetadata *f,
16 Instance **ret) {
17
18 _cleanup_(instance_freep) Instance *i = NULL;
19 _cleanup_free_ char *p = NULL, *v = NULL;
20
21 assert(rr);
22 assert(path);
23 assert(f);
24 assert(f->version);
25 assert(ret);
26
27 p = strdup(path);
28 if (!p)
29 return log_oom();
30
31 v = strdup(f->version);
32 if (!v)
33 return log_oom();
34
35 i = new(Instance, 1);
36 if (!i)
37 return log_oom();
38
39 *i = (Instance) {
40 .resource = rr,
41 .metadata = *f,
42 .path = TAKE_PTR(p),
43 .partition_info = PARTITION_INFO_NULL,
44 };
45
46 i->metadata.version = TAKE_PTR(v);
47
48 *ret = TAKE_PTR(i);
49 return 0;
50 }
51
52 Instance *instance_free(Instance *i) {
53 if (!i)
54 return NULL;
55
56 instance_metadata_destroy(&i->metadata);
57
58 free(i->path);
59 partition_info_destroy(&i->partition_info);
60
61 return mfree(i);
62 }