From: Yu Watanabe Date: Tue, 18 Sep 2018 03:50:33 +0000 (+0900) Subject: hwdb: use _cleanup_ attribute at one more place X-Git-Tag: v240~707^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d7783e93795f6fa247423bb8f57f2b951666124;p=thirdparty%2Fsystemd.git hwdb: use _cleanup_ attribute at one more place --- diff --git a/src/hwdb/hwdb.c b/src/hwdb/hwdb.c index a2c1f7da22c..bdd0ba3c2a2 100644 --- a/src/hwdb/hwdb.c +++ b/src/hwdb/hwdb.c @@ -202,9 +202,9 @@ static int trie_insert(struct trie *trie, struct trie_node *node, const char *se struct trie_node *child; for (p = 0; (c = trie->strings->buf[node->prefix_off + p]); p++) { + _cleanup_free_ struct trie_node *new_child = NULL; _cleanup_free_ char *s = NULL; ssize_t off; - _cleanup_free_ struct trie_node *new_child = NULL; if (c == search[i + p]) continue; @@ -250,26 +250,24 @@ static int trie_insert(struct trie *trie, struct trie_node *node, const char *se child = node_lookup(node, c); if (!child) { + _cleanup_free_ struct trie_node *new_child = NULL; ssize_t off; /* new child */ - child = new0(struct trie_node, 1); - if (!child) + new_child = new0(struct trie_node, 1); + if (!new_child) return -ENOMEM; off = strbuf_add_string(trie->strings, search + i+1, strlen(search + i+1)); - if (off < 0) { - free(child); + if (off < 0) return off; - } - child->prefix_off = off; - r = node_add_child(trie, node, child, c); - if (r < 0) { - free(child); + new_child->prefix_off = off; + r = node_add_child(trie, node, new_child, c); + if (r < 0) return r; - } + child = TAKE_PTR(new_child); return trie_node_add_value(trie, child, key, value, filename, file_priority, line_number); }