Since the malloc()s are used to build trees etc in this code, I would advice having two arrays of structs, and then for each malloc() you pick one from the list to use and mark it as used - simulating malloc(). The number of array entries would need to be tweaked to work with a suitable worst case.