Skip to content
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

coap_add_attr() does not take ownership over passed data(name/val) #10

Closed
DoumanAsh opened this issue Sep 9, 2015 · 2 comments
Closed

Comments

@DoumanAsh
Copy link

https://github.com/obgm/libcoap/blob/develop/src/resource.c#L333-L334

I understand that as of current it is user's responsibility to ensure that passed pointers are valid.
But i think it would be more rational for coap_attr_t struct to take ownership over passed values.
After all this strcture belongs to resource now and user should not change values inside of it without using a proper API. Though there is none for such needs as of current...

I didn't look into other places, but i would generally think that taking ownership of all resources would be right for library and its structures. Otherwise the line between library and application becomes dim.

UPD:
The same for uri in coap_resource_init

@obgm
Copy link
Owner

obgm commented Jan 9, 2016

coap_add_attr() and coap_resource_init() actually take ownership of the passed pointers. Whether or not the storage pointed to by these pointers is released on destruction of the respective attribute or resource object is controlled by the flags parameter:

  • COAP_RESOURCE_FLAGS_RELEASE_URI causes the resource URI that was passed to coap_resource_init() to be freed when the resource is deleted by coap_delete_resource().
  • COAP_ATTR_FLAGS_RELEASE_NAME and COAP_ATTR_FLAGS_RELEASE_VALUE similarly control the deletion of attribute name and attribute value in coap_delete_attr().

Using these attributes, you can pass literal character strings such as those used in the example server application as well as dynamically generated strings easily. Note that libcoap specifically has been designed to provide a very tight coupling between low-level operations and the application that use this library to meet the requirement of highly-optimized embedded applications.

@obgm obgm closed this as completed Jan 9, 2016
@DoumanAsh
Copy link
Author

Oh... I see...
Sorry for raising this issue.

mrdeep1 added a commit to mrdeep1/libcoap that referenced this issue Dec 17, 2022
mrdeep1 added a commit to mrdeep1/libcoap that referenced this issue Dec 20, 2022
mrdeep1 added a commit to mrdeep1/libcoap that referenced this issue Dec 30, 2022
mrdeep1 added a commit to mrdeep1/libcoap that referenced this issue Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants