I don't know if this is a stupid statement or not but I somehow expected more malloc's in this code. I'm fairly confident that you have to actually malloc the deeper branches of the tree, right? Or...