summaryrefslogtreecommitdiff
path: root/src/hwdb
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-09-18 12:50:33 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-09-19 16:52:59 +0900
commit4d7783e93795f6fa247423bb8f57f2b951666124 (patch)
tree9ee77d193cce21e1c7fa0d234ed142c795818495 /src/hwdb
parentbf84dc168c23872a3e6b37c3daa5d26950c82bda (diff)
downloadsystemd-4d7783e93795f6fa247423bb8f57f2b951666124.tar.gz
hwdb: use _cleanup_ attribute at one more place
Diffstat (limited to 'src/hwdb')
-rw-r--r--src/hwdb/hwdb.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/hwdb/hwdb.c b/src/hwdb/hwdb.c
index a2c1f7da22..bdd0ba3c2a 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);
}