Assertion failed: fr->magic == FLI_MAGIC

Hi.
I’m using the prolog C interface. Basically i write foreign predicates in C and then call them from prolog. Several of my C functions use dynamic memory allocation (free etc). When i test a program that uses a lot of memory, i get the error swipl-devel/src/pl-gc.c:996: mark_term_refs: Assertion failed: fr->magic == FLI_MAGIC. What does the assertion failed means? And the flag FLI_MAGIC? Can the error be caused by a memory leak in the C code (for instance, a missing call to a free)? I’m using: SWI-Prolog version 8.1.7-9-ge6fe9c5.

Thanks

It could be that some memory is getting corrupted.

Try running with swipl -d chk_secure which will enable some extra debugging/checks to see if you are corrupting a termref or something earlier in your code.

See this post:

This page has more info also:

http://www.swi-prolog.org/pldoc/man?section=foreign-debug

The error merely indicates a corruption of the Prolog stacks. This us usually caused by not understanding the term_t, qid_t and fid_t scoping rules. Compiling Prolog for debugging (see CMAKE.md) and using the -d chk_secure may, as @swi says, help locating the issue.

There can of course be general memory management issues in your application that causes some dangling pointer to corrupt Prolog’s memory areas. Corruption mostly shows up as assertion failures during garbage collection. Use whatever tools are best for your platform or you are familiar with to track down memory management issues.