我在许多项目中使用 asn1c 库,但我从未找到如何使用SEQUENCE_OF. 因此,我总是将其设置为nullptr,当我使用 Valgrind 时,我发现(当然)在ASN_STRUCT_FREE包含列表的元素上使用时,我的列表成员没有被释放。
所以我的问题是如何使用该免费会员?
这是我如何将列表与 asn1c 一起使用的简单示例。
ListItem_t *li = nullptr;
StructWList_t swl;
swl.list.count = 0;
swl.list.size = 0;
swl.list.free = nullptr; // How can I feed it properly?
swl.list.array = reinterpret_cast<ListItem_t**>(calloc(1, sizeof *swl.list.array));
for(int i = 0 ; i < 5 ; i++)
{
li = reinterpret_cast<ListItem_t*>(calloc(1, sizeof *li));
*li = i;
// Valgrind says that the calloc below is definitly lost
swl.list.array[i] = reinterpret_cast<ListItem_t*>(calloc(1, sizeof *swl.list.array[i]));
ASN_SEQUENCE_ADD(&swl, li);
} …Run Code Online (Sandbox Code Playgroud)