-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: CBOR Key/Value Arrays are interpreted correctly but do not deallocate correctly. #194
Comments
Here is the solution that I have currently implemented for the problem. It would be nice if the developers review this fix within cbor_decref: |
Hi @kbranner , thank you for the bug report, could you please provide a full code example to reproduce the bug? cbor_array_push incrementing the reference count seems to WAI on the surface because both the array and the caller will hold a reference to the item. You can |
Hi PJK. I don't want to use cbor_move but simply interpret the full CBOR object and then de allocate it with a cbor_decref from the root. These objects CBOR objects in our application can get quite large - for example 65K bytes so trying to do cbor moves will add another layer of complexity. |
Just to be clear, cbor_move doesn't actually do any memory allocation or copying, it simply decrements the reference count without deallocating the object with the assumption that the callee is taking ownership of it, so I think it does exactly what you want (release the handle in the current scope and only keep the pushed objects in the array) |
Hi PJK - Ok will give it a try and will report results back to you. |
Hi PJK Suggestions#2: Perhaps you could introduce a new command such as cbor_deallocate(cbor_item_t **item_ref). This command will automatically de-allocate all elements from parameter item that was passed without the user requiring intimate knowledge details of the libcbor library. Also thanks for this library and your continued support. |
Glad to hear! Re 1: Makes sense, filed #195 Re 2: Doesn't cbor_decref do what you want? You can find more at https://libcbor.readthedocs.io/en/latest/api/item_reference_counting.html |
The JSON object shown below when translated to CBOR will be interpreted correctly , but the array key/value pair will never be de allocated using the cbor_decref call.
It turns out that for some reason the refcount for those items are set to a value of 2. So the cbor_decref(cbor_item_t **item_ref) function ignores refcounts > 1.
The reason why this occurs is because within the cbor_array_push function the cbor_incref(pushee) call will increment an item's refcount from 1 to 2.
For those items within the array they never get released by cbor_decref because of the requirement that their refcount must be equal to 1.
{
"state":
{
"desired":
{
"array" : [360,0,0,0,0,0,0,0]
}
}
}
The text was updated successfully, but these errors were encountered: