【发布时间】:2019-05-07 09:06:33
【问题描述】:
我在许多项目中都使用 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);
}
...
ASN_STRUCT_FREE(ASN_DEF_StructWList, &swl);
有人知道如何正确喂食吗?
编辑
我的 asn1c 版本是来自 AUR 的 git 存储库的 v0.9.29(在 Archlinux 上)。
以上ASN.1如下:
Example
DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
StructWList ::= SEQUENCE OF ListItem
ListItem ::= INTEGER
END
提前致谢,
艾米莉安
【问题讨论】:
-
您使用哪个 asn1c 版本,您能否分享上述示例的 asn.1 定义?
-
@VasilVelichkov 我在编辑部分的回复。
-
AUR 中的版本是 0.9.27-3 aur.archlinux.org/packages/asn1c 而不是 v0.9.29。你能给我 git commit id 吗?
-
用当前主控github.com/vlm/asn1c/tree/…的asn1c编译上述定义后,
ASN_DEF_StructWList没有定义。你手动定义了吗,能给我定义吗?