mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Add json_object_object_add_by_uint_by_ref helper.
Function is similar to json_object_object_add_by_uint but it unsets *jobj_val_ref pointer if the function ends with success. It helps to create cleaner error patch and avoids eventual double free corruption if **jobj_val_ref object changed ownership.
This commit is contained in:
@@ -62,6 +62,7 @@ uint32_t crypt_jobj_get_uint32(json_object *jobj);
|
||||
json_object *crypt_jobj_new_uint64(uint64_t value);
|
||||
|
||||
int json_object_object_add_by_uint(json_object *jobj, unsigned key, json_object *jobj_val);
|
||||
int json_object_object_add_by_uint_by_ref(json_object *jobj, unsigned key, json_object **jobj_val_ref);
|
||||
void json_object_object_del_by_uint(json_object *jobj, unsigned key);
|
||||
int json_object_copy(json_object *jobj_src, json_object **jobj_dst);
|
||||
|
||||
|
||||
@@ -2867,6 +2867,20 @@ int json_object_object_add_by_uint(json_object *jobj, unsigned key, json_object
|
||||
#endif
|
||||
}
|
||||
|
||||
int json_object_object_add_by_uint_by_ref(json_object *jobj, unsigned key, json_object **jobj_val_ref)
|
||||
{
|
||||
int r;
|
||||
|
||||
assert(jobj);
|
||||
assert(jobj_val_ref);
|
||||
|
||||
r = json_object_object_add_by_uint(jobj, key, *jobj_val_ref);
|
||||
if (!r)
|
||||
*jobj_val_ref = NULL;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/* jobj_dst must contain pointer initialized to NULL (see json-c json_object_deep_copy API) */
|
||||
int json_object_copy(json_object *jobj_src, json_object **jobj_dst)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user