summaryrefslogtreecommitdiff
path: root/src/lib/btree.c
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@ugent.be>2017-08-29 11:23:52 +0000
committerdimitri staessens <dimitri.staessens@ugent.be>2017-08-29 11:23:52 +0000
commit00aeb6ee00efa98c7e2d6d9bebeb1c4799ba1705 (patch)
treed86a1c02b36cfc5feea1ba5f22c6899f8a6c0c9c /src/lib/btree.c
parente8875c08ac04a1d9aca342d94d4f788239334f72 (diff)
parent4de841c26b7208d5395da349ea16c937b1361414 (diff)
downloadouroboros-00aeb6ee00efa98c7e2d6d9bebeb1c4799ba1705.tar.gz
ouroboros-00aeb6ee00efa98c7e2d6d9bebeb1c4799ba1705.zip
Merged in sandervrijders/ouroboros/be-bugfixes (pull request #573)
lib, ipcpd, irmd: Fix bugs reported by static analysis
Diffstat (limited to 'src/lib/btree.c')
-rw-r--r--src/lib/btree.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/lib/btree.c b/src/lib/btree.c
index 8be8b99f..beba90f7 100644
--- a/src/lib/btree.c
+++ b/src/lib/btree.c
@@ -85,6 +85,8 @@ static struct btnode * btnode_create(size_t k)
if (node == NULL)
return NULL;
+ assert(k > 0);
+
node->keyvals = malloc(sizeof(*node->keyvals) * k);
if (node->keyvals == NULL) {
free(node);
@@ -368,8 +370,10 @@ struct btree * btree_create(size_t k)
if (tree == NULL)
return NULL;
- if (k > BTREE_MAX_ORDER)
+ if (k < 1 || k > BTREE_MAX_ORDER) {
+ free(tree);
return NULL;
+ }
tree->k = k;
tree->root = NULL;
@@ -413,8 +417,10 @@ int btree_insert(struct btree * tree,
if (rgt != NULL) {
struct btnode * lft = btnode_create(tree->root->k);
- if (lft == NULL)
+ if (lft == NULL) {
+ free(rgt);
return -ENOMEM;
+ }
lft->used = tree->root->used;
lft->leaf = tree->root->leaf;