summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-06-12 17:24:38 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-06-17 17:26:15 +0200
commit6548aef1cdb56dc3afcd2f474619888561d8f454 (patch)
tree8003b88cfd48a30370345cdad258d0bc2fc2e62e /src
parentstrbuf: several cleanups (diff)
downloadsystemd-6548aef1cdb56dc3afcd2f474619888561d8f454.tar.xz
systemd-6548aef1cdb56dc3afcd2f474619888561d8f454.zip
strbuf: use _cleanup_ attribute at one more place
Diffstat (limited to 'src')
-rw-r--r--src/basic/strbuf.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/basic/strbuf.c b/src/basic/strbuf.c
index e12c0f9b11..a53d733594 100644
--- a/src/basic/strbuf.c
+++ b/src/basic/strbuf.c
@@ -27,24 +27,22 @@
*/
struct strbuf* strbuf_new(void) {
- struct strbuf *str;
+ _cleanup_(strbuf_freep) struct strbuf *str = NULL;
str = new(struct strbuf, 1);
if (!str)
return NULL;
+
*str = (struct strbuf) {
.buf = new0(char, 1),
.root = new0(struct strbuf_node, 1),
.len = 1,
.nodes_count = 1,
};
- if (!str->buf || !str->root) {
- free(str->buf);
- free(str->root);
- return mfree(str);
- }
+ if (!str->buf || !str->root)
+ return NULL;
- return str;
+ return TAKE_PTR(str);
}
static struct strbuf_node* strbuf_node_cleanup(struct strbuf_node *node) {