C port of the code described here: http://www.codeofhonor.com/blog/avoiding-game-crashes-related-to-linked-lists