From 6548aef1cdb56dc3afcd2f474619888561d8f454 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 13 Jun 2024 00:24:38 +0900 Subject: [PATCH] strbuf: use _cleanup_ attribute at one more place --- src/basic/strbuf.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/basic/strbuf.c b/src/basic/strbuf.c index e12c0f9b113..a53d7335948 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) { -- 2.47.3