]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/basic/strbuf.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / basic / strbuf.c
index 797f00cf7165f52485d659f2f80c23eaa49c6e4c..8befffa66fd184bad022a5017e26da021515bcfb 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
 /***
   This file is part of systemd.
 
@@ -62,8 +63,7 @@ struct strbuf *strbuf_new(void) {
 err:
         free(str->buf);
         free(str->root);
-        free(str);
-        return NULL;
+        return mfree(str);
 }
 
 static void strbuf_node_cleanup(struct strbuf_node *node) {
@@ -156,12 +156,13 @@ ssize_t strbuf_add_string(struct strbuf *str, const char *s, size_t len) {
                         return off;
                 }
 
+                c = s[len - 1 - depth];
+
                 /* bsearch is not allowed on a NULL sequence */
                 if (node->children_count == 0)
                         break;
 
                 /* lookup child node */
-                c = s[len - 1 - depth];
                 search.c = c;
                 child = bsearch(&search, node->children, node->children_count,
                                 sizeof(struct strbuf_child_entry),