The return value was checked on all calls to r3_slug_find_placeholder()
except in one place, which triggered a Coverity warning.
This adds a check (assert), and enables the other asserts for non-debug
builds to catch segmentation faults early.
When inserting multiple routes with common slug patterns
there are reads beyond end of strings.
The scenario is added as a testcase and can be triggered by
the address-sanitizer when built using:
`CFLAGS="-fno-omit-frame-pointer -fsanitize=address" cmake ..`
Indicated as a `buffer-overflow`
When `r3_node_find_common_prefix()` searches for the common prefix it
selects the first matched edge, which might not be the best match.
This issue gives memoryleaks which can be viewed in legacy
testcase `check_tree::test_insert_pathl()` by building using:
`CFLAGS="-fno-omit-frame-pointer -fsanitize=leak" cmake ..`
See testcase procedures:
ret = r3_tree_insert_path(n, "/foo/{id}", NULL);
..
ret = r3_tree_insert_path(n, "/foo/{idx}/{idy}", NULL);
..
ret = r3_tree_insert_path(n, "/foo/{idx}/{idh}", NULL); <-- leaks
Also added a testcase that triggers the problem including a leak for
reproduction on baseline.
background : use r3_tree_insert_pathl_ex to add path,A : abcdefg B:abc
When the node A already exists, we set B, then will split the node and make a branch, suboath_len is 0
In this case, branch a zero len subpath, which tree's data not set
change: code style, delete some useless spaces(visual code).
eg:
warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result
This patch fixes a few issues in the check_tree test:
* Fix various memory leaks in test code
* Fix a double-free in test code
* Fix a memory leak in r3_tree_compile_patterns
One memory leak remains in the library code but it isn't obvious to me
how to fix it at the moment.