mirror of
https://github.com/obgm/libcoap.git
synced 2026-12-03 03:01:05 +03:00
options: Fix subtle memory leak in coap_add_optlist_pdu()
coap_add_optlist_pdu() sorted the options for insertion, but did not update the coap_optlist_t head (whch may then no longer point to the first entry in the sorted chain) and so when coap_delete_optlist() was called, the first few entries of the sorted chain may not get deleted. Fixed by making it coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t** optlist_chain) instead of coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t* optlist_chain) Additionally deleted options_start() and options_next() as they are not required - Issue #184. examples/client.c: Fix coap_add_optlist_pdu() call include/coap/options.h: Fix coap_add_optlist_pdu() call libcoap-2.{map|sym}: Delete options_start() man/coap_observe.txt.in: man/coap_pdu_setup.txt.in: Update docmentation src/option.c: Update coap_add_optlist_pdu() tests/test_pdu.c: New tests for checkout out coap_insert_optlist() and coap_add_optlist_pdu() functions
This commit is contained in:
1 parent
232f2612f2
commit
9fa448e439
6 files changed
+120
-36
No files matched your search
+2
-18
@@ -61,22 +61,6 @@ size_t coap_opt_parse(const coap_opt_t *opt,
|
||||
*/
|
||||
size_t coap_opt_size(const coap_opt_t *opt);
|
||||
|
||||
/**
|
||||
* Calculates the beginning of the PDU's option section.
|
||||
*
|
||||
* @param pdu The PDU containing the options.
|
||||
* @return A pointer to the first option if available, or @c NULL otherwise.
|
||||
*/
|
||||
coap_opt_t *options_start(coap_pdu_t *pdu);
|
||||
|
||||
/**
|
||||
* Interprets @p opt as pointer to a CoAP option and advances to
|
||||
* the next byte past this option.
|
||||
* @hideinitializer
|
||||
*/
|
||||
#define options_next(opt) \
|
||||
((coap_opt_t *)((uint8_t *)(opt) + coap_opt_size(opt)))
|
||||
|
||||
/**
|
||||
* @defgroup opt_filter Option Filters
|
||||
* @{
|
||||
@@ -415,7 +399,7 @@ const uint8_t *coap_opt_value(const coap_opt_t *opt);
|
||||
* coap_insert_optlist(&optlist_chain, coap_new_optlist(COAP_OPTION_OBSERVE,
|
||||
* COAP_OBSERVE_ESTABLISH, NULL));
|
||||
*
|
||||
* coap_add_optlist_pdu(pdu, *optlist_chain);
|
||||
* coap_add_optlist_pdu(pdu, &optlist_chain);
|
||||
* ... other code ...
|
||||
* coap_delete_optlist(optlist_chain);
|
||||
* @endcode
|
||||
@@ -449,7 +433,7 @@ coap_optlist_t *coap_new_optlist(uint16_t number,
|
||||
*
|
||||
* @return @c 1 if succesful or @c 0 if failure;
|
||||
*/
|
||||
int coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t* optlist_chain);
|
||||
int coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t** optlist_chain);
|
||||
|
||||
/**
|
||||
* Adds @p optlist to the given @p optlist_chain. The optlist_chain variable
|
||||
|
||||
Reference in new issue
Block a user