Config tree IteratorRef != NULL

I’m getting this error when trying to cancel the read even though it prints out the string im trying to get why would the iterator not be removed?
The issue is on the second to last line
le_cfg_CancelTxn(iteratorRef);

Anyone know thanks?

Jun 7 01:19:51 fx30 user.emerg Legato: EMR | configTree[1004]/configTree T=main | nodeIterator.c ni_InternalRefFromExternalRef() 364 | Assert Failed: ‘iteratorRef != NULL’

le_result_t FromTree()
{

    le_result_t result;
char popped[50];
char nameBuffer[LE_CFG_STR_LEN_BYTES] = { 0 };
int r = snprintf(nameBuffer, sizeof(nameBuffer), "/MQTTBUF");
if (r < 0)
{
	return LE_FAULT;
}
else if (r >= sizeof(nameBuffer))
{
	return LE_OVERFLOW;
}
le_cfg_IteratorRef_t iteratorRef = le_cfg_CreateReadTxn(nameBuffer);
if (le_cfg_NodeExists(iteratorRef, "") == false)
{
	//LE_WARN("Configuration not found.");
	le_cfg_CancelTxn(iteratorRef);
	return LE_NOT_FOUND;
}
le_cfg_GoToFirstChild(iteratorRef);
le_cfg_GetPath(iteratorRef,"",popped,80);
LE_INFO("Location %s",popped);
result = le_cfg_GetString(iteratorRef,"",popped,80,"");
LE_INFO("popping %s",popped);                         //<----------- This works
if (result != LE_OK)
{
	le_cfg_CancelTxn(iteratorRef);
	return result;
}
le_cfg_CancelTxn(iteratorRef);         //<---------------- issue is on this line
return LE_OK;

}

EDIT: The app isn’t sandboxed and I’m wondering if that’s causing problems.
EDIT: reading from a root tree causes the above error so now im writing in the apps tree and it gives this error

Assert Failed: ‘le_pack_PackReference( &_msgBufPtr, &_msgBufSize, iteratorRef )’

Ok Seems to be fixed now just moved the Path to inside the app its and changed the get string line to le_cfg_GetString(iteratorRef,"",popped,LE_CFG_STR_LEN_BYTES,"");
and static char popped[LE_CFG_STR_LEN_BYTES] = “”;

Actually I still seem to be getting this error alot?

I’m having issues with the readtimer expiring randomly now can it clash with the write transaction? Is there a way to block reading until writing is finished I think whats happening is I start reading and mid way through it starts writing but it can’t commit the writing because its still reading.

EDIT:
I’ve got two issues one seems to if I open a read transaction on an empty tree (how do I check this?) I get an issue where I can’t close the transaction and it just times out and kills my apps. The other is when I try to write while reading; tried to fix this by making two apps and sharing a tree but for some reason only one can have read perms and one can have write but I need to delete nodes after reading which is a pain.

I also feel like its not returning the right sized strings? how can I allocate the correct memory for this? Is LE_CFG_STR_LEN_BYTES going to set the returned string length correctly or does it just stick a NULL terminator at the 511th byte I assume not but its weird?

welp I don’t know what causes all the other issues but the IteratorRef!=NULL is caused by le_cfg_GoToFirstChild(iteratorRef); without one existing yet.

Sadly because I don’t know the name of the child I can’t check if it exists/is empty and my application crashes and restarts the whole device.

Even just doing this causes it to crash

if (le_cfg_IsEmpty(iteratorRef, “”) == true)
{
LE_WARN(“Configuration not found.”); <-- says not found
le_cfg_CancelTxn(iteratorRef); <-- cannot cancel and it reboots system
}

Ok I just removed CancelTxn from the isempty check and it works all good
If its empty don’t cancel the transcation

@sast5 Thanks this was a big help!