I found my threaded tree code, and unfortunately back then when I tried it I used seperate prev & next pointers as well as left & right pointers, and never got around to combining them and using flags. I do remember that it was one of the trickier things I wrote back then.
If I read your code correctly, you're constructing the tree and then modifying it to be threaded afterwards? Mine was a threaded-AVL-tree which was threaded from the beginning. It's so different thast the code would be no user whatsoever to you.
Is 'link' simply meant to find the successor? Something that jumps out at me as being very wrong is that there's a call to 'free' in there.