Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2016-06-21 18:19:10 +0300
committerFelix Fietkau <nbd@nbd.name>2016-06-26 13:53:51 +0300
commit1f019ceea1ed39286e6bccfb3ff936c22fe0f7c0 (patch)
tree92ec3e71ca90b1bb12ff930ac1b7abfa8c1d0e07 /kvlist.c
parentc2f2c47f3e9a2d709ec82a79f6fadd3124c18781 (diff)
Fix various memory management issues
Consistently handle allocation failures. Some functions are changed to return bool or int instead of void to allow returning an error. Also fix a buffer size miscalculation in lua/uloop and use _exit() instead of exit() on errors after forking. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
Diffstat (limited to 'kvlist.c')
-rw-r--r--kvlist.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/kvlist.c b/kvlist.c
index e0a8acb..a7b6ea0 100644
--- a/kvlist.c
+++ b/kvlist.c
@@ -71,20 +71,25 @@ bool kvlist_delete(struct kvlist *kv, const char *name)
return !!node;
}
-void kvlist_set(struct kvlist *kv, const char *name, const void *data)
+bool kvlist_set(struct kvlist *kv, const char *name, const void *data)
{
struct kvlist_node *node;
char *name_buf;
int len = kv->get_len(kv, data);
- kvlist_delete(kv, name);
-
node = calloc_a(sizeof(struct kvlist_node) + len,
&name_buf, strlen(name) + 1);
+ if (!node)
+ return false;
+
+ kvlist_delete(kv, name);
+
memcpy(node->data, data, len);
node->avl.key = strcpy(name_buf, name);
avl_insert(&kv->avl, &node->avl);
+
+ return true;
}
void kvlist_free(struct kvlist *kv)