From: Yu Watanabe Date: Wed, 12 Jun 2024 15:24:38 +0000 (+0900) Subject: strbuf: use _cleanup_ attribute at one more place X-Git-Tag: v257-rc1~1122^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F33377%2Fhead;p=thirdparty%2Fsystemd.git strbuf: use _cleanup_ attribute at one more place --- 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) {