summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-30 20:32:56 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-31 14:34:24 -0400
commita9c307e5d2157c561eae7fc76303cadf7a77b99e (patch)
tree581674692b3852bc59ed54c6e0f053ad2fb80b8b
parent522cd7f18bf1e4a024d6771186a0149c5ca8109c (diff)
strbuf: fix leak on memory error
Not very likely, but let's fix it for the matter of principle.
-rw-r--r--src/shared/strbuf.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/shared/strbuf.c b/src/shared/strbuf.c
index 915cd3ac99..abc5c0dd29 100644
--- a/src/shared/strbuf.c
+++ b/src/shared/strbuf.c
@@ -158,14 +158,18 @@ ssize_t strbuf_add_string(struct strbuf *str, const char *s, size_t len) {
node_child = new0(struct strbuf_node, 1);
if (!node_child)
return -ENOMEM;
- str->nodes_count++;
node_child->value_off = off;
node_child->value_len = len;
/* extend array, add new entry, sort for bisection */
child = realloc(node->children, (node->children_count + 1) * sizeof(struct strbuf_child_entry));
- if (!child)
+ if (!child) {
+ free(node_child);
return -ENOMEM;
+ }
+
+ str->nodes_count++;
+
node->children = child;
node->children[node->children_count].c = c;
node->children[node->children_count].child = node_child;