]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
strbuf: use _cleanup_ attribute at one more place 33377/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 12 Jun 2024 15:24:38 +0000 (00:24 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 17 Jun 2024 15:26:15 +0000 (00:26 +0900)
src/basic/strbuf.c

index e12c0f9b1133ed5501a8285bafc121cced25134c..a53d73359489f5d4a41be6a3bc6f64471415d1e7 100644 (file)
  */
 
 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) {