diff options
Diffstat (limited to 'json_object.c')
-rw-r--r-- | json_object.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/json_object.c b/json_object.c index 6060554..39c9327 100644 --- a/json_object.c +++ b/json_object.c @@ -371,7 +371,7 @@ struct lh_table* json_object_get_object(struct json_object *jso) } } -void json_object_object_add(struct json_object* jso, const char *key, +int json_object_object_add(struct json_object* jso, const char *key, struct json_object *val) { // We lookup the entry and replace the value, rather than just deleting @@ -381,13 +381,19 @@ void json_object_object_add(struct json_object* jso, const char *key, existing_entry = lh_table_lookup_entry(jso->o.c_object, (void*)key); if (!existing_entry) { - lh_table_insert(jso->o.c_object, strdup(key), val); - return; + char * keydup = strdup( key ); + if ( keydup == NULL ) { + return -1; + } + + return lh_table_insert(jso->o.c_object, keydup, val); } existing_value = (void *)existing_entry->v; if (existing_value) json_object_put(existing_value); existing_entry->v = val; + + return 0; } struct json_object* json_object_object_get(struct json_object* jso, const char *key) |