Plug resource leaks in aclresrouce for valgrind
Plug resource leaks in aclresrouce for valgrind

Fix some resource leaks caused by string allocation on POST
requests. These occur in CBORPayloadToAclVersionOpt. There are
two areas:

(1) tagName is allocated via cbor_value_dup_text_string, but
conditions allow an escape without cleaning via a return statement.
Calls to free added at the escape points.  Cleans these
four reports:

8 bytes in 1 blocks are definitely lost in loss record 21 of 270
   at 0x4C2EB6B: malloc (vg_replace_malloc.c:299)
   by 0x52FD83: _cbor_value_dup_string (cborparser_dup_string.c:102)
   by 0x4BFF0F: cbor_value_dup_text_string (cbor.h:394)
   by 0x4CAB1F: CBORPayloadToAclVersionOpt (aclresource.c:1437)
   by 0x4D2FE0: HandleACLPostRequest (aclresource.c:2886)
   by 0x4D4212: ACLEntityHandler (aclresource.c:3182)
   by 0x41234F: ACLResourceTest_ACLPostTest_Test::TestBody() (aclresourcetest.cpp:323)

8 bytes in 1 blocks are definitely lost in loss record 22 of 270
   at 0x4C2EB6B: malloc (vg_replace_malloc.c:299)
   by 0x52FD83: _cbor_value_dup_string (cborparser_dup_string.c:102)
   by 0x4BFF0F: cbor_value_dup_text_string (cbor.h:394)
   by 0x4CAB1F: CBORPayloadToAclVersionOpt (aclresource.c:1437)
   by 0x4D2FE0: HandleACLPostRequest (aclresource.c:2886)
   by 0x4D4212: ACLEntityHandler (aclresource.c:3182)
   by 0x4154AE: ACLResourceTest_ACLDeleteWithSingleResourceTest_Test::TestBody() (aclresourcetest.cpp:479)

8 bytes in 1 blocks are definitely lost in loss record 23 of 270
   at 0x4C2EB6B: malloc (vg_replace_malloc.c:299)
   by 0x52FD83: _cbor_value_dup_string (cborparser_dup_string.c:102)
   by 0x4BFF0F: cbor_value_dup_text_string (cbor.h:394)
   by 0x4CAB1F: CBORPayloadToAclVersionOpt (aclresource.c:1437)
   by 0x4D2FE0: HandleACLPostRequest (aclresource.c:2886)
   by 0x4D4212: ACLEntityHandler (aclresource.c:3182)
   by 0x416FF2: ACLResourceTest_ACLDeleteWithMultiResourceTest_Test::TestBody() (aclresourcetest.cpp:539)

8 bytes in 1 blocks are definitely lost in loss record 24 of 270
   at 0x4C2EB6B: malloc (vg_replace_malloc.c:299)
   by 0x52FD83: _cbor_value_dup_string (cborparser_dup_string.c:102)
   by 0x4BFF0F: cbor_value_dup_text_string (cbor.h:394)
   by 0x4CAB1F: CBORPayloadToAclVersionOpt (aclresource.c:1437)
   by 0x4D2FE0: HandleACLPostRequest (aclresource.c:2886)
   by 0x4D4212: ACLEntityHandler (aclresource.c:3182)
   by 0x418DF0: ACLResourceTest_ACLGetWithQueryTest_Test::TestBody() (aclresourcetest.cpp:606)

(2) subjectTag is allocated via cbor_value_dup_text_string, which
can happen several times inside a loop.  There is a clean at the exit
point of the function, but that does not help if it has been allocated
several times in the loop, as each one will cause the reference to
the previous allocation to be lost.  A free is added at the last point
of use, and the generic one at the end which is no longer needed
is removed.  Cleans these three reports:

27 bytes in 3 blocks are definitely lost in loss record 124 of 270
   at 0x4C2EB6B: malloc (vg_replace_malloc.c:299)
   by 0x52FD83: _cbor_value_dup_string (cborparser_dup_string.c:102)
   by 0x4BFF0F: cbor_value_dup_text_string (cbor.h:394)
   by 0x4CBFE3: CBORPayloadToAclVersionOpt (aclresource.c:1630)
   by 0x4D0035: CBORPayloadToAcl (aclresource.c:2087)
   by 0x4108AA: ACLResourceTest_GetDefaultACLTests_Test::TestBody() (aclresourcetest.cpp:263)

41 bytes in 5 blocks are definitely lost in loss record 151 of 270
   at 0x4C2EB6B: malloc (vg_replace_malloc.c:299)
   by 0x52FD83: _cbor_value_dup_string (cborparser_dup_string.c:102)
   by 0x4BFF0F: cbor_value_dup_text_string (cbor.h:394)
   by 0x4CBFE3: CBORPayloadToAclVersionOpt (aclresource.c:1630)
   by 0x4D0035: CBORPayloadToAcl (aclresource.c:2087)
   by 0x4D30C4: HandleACLPostRequest (aclresource.c:2897)
   by 0x4D4212: ACLEntityHandler (aclresource.c:3182)
   by 0x41234F: ACLResourceTest_ACLPostTest_Test::TestBody() (aclresourcetest.cpp:323)

41 bytes in 5 blocks are definitely lost in loss record 152 of 270
   at 0x4C2EB6B: malloc (vg_replace_malloc.c:299)
   by 0x52FD83: _cbor_value_dup_string (cborparser_dup_string.c:102)
   by 0x4BFF0F: cbor_value_dup_text_string (cbor.h:394)
   by 0x4CBFE3: CBORPayloadToAclVersionOpt (aclresource.c:1630)
   by 0x4D0035: CBORPayloadToAcl (aclresource.c:2087)
   by 0x412381: ACLResourceTest_ACLPostTest_Test::TestBody() (aclresourcetest.cpp:324)

Change-Id: I538dbb69fff94954a17f4ab95142c6e37177efb9
Bug: https://jira.iotivity.org/browse/IOT-2701
Signed-off-by: Mats Wichmann <7a5e6f27299d2bbd9d04b59d9e8e4f8eab83d8cb@linux.com>

iotivity/iotivity,iotivity/iotivity,iotivity/iotivity,rzr/iotivity,rzr/iotivity,rzr/iotivity,iotivity/iotivity,rzr/iotivity,rzr/iotivity,iotivity/iotivity,rzr/iotivity,iotivity/iotivity,iotivity/iotivity,iotivity/iotivity,rzr/iotivity