4 bugs removed

Just now, I’ve removed 4 bugs from SIEGE (they were found quickly with a bit of help of Valgrind) – this means that SIEGE now exits with no memory leaks whatsoever (well, none that Valgrind could find with the app I tested with) and that it’s clean on the Valgrind end.

The first two bugs were in the implementation of SGList (linked lists) – in freeing of the list:

if(list->internalFree != NULL;

…and an individual node:

if(node->internalFree != NULL;

This normally isn’t a problem, however the issue is that neither internalFree was set anywhere – that means that “internalFree” was undefined (could have any value), and as such, the program would segfault on exit.

The other problem was in deinit of viewports and the modules – both had code which was similar to this:

SGListNode* node;
for(node = _sg_viewList->first; node != NULL; node = node->next)

Look carefully – the viewport at the node is destroyed (which also destroys the node), after which “node = node->next” is ran – by that time, the previous node has been free’d, and its contents are thus undefined. The solution was simple:

SGListNode* node;
SGListNode* next;
for(node = _sg_viewList->first; node != NULL; node = next)
    next = node->next;

So there you have it – the problems which were pestering SIEGE’s otherwise clean shutdown are now gone.

Posted in SIEGE.