There is a good talk through of this problem, complete with a pretty much optimal algorithm here:
http://www.akalin.cx/longest-palindrome-linear-time[
^]
It works by looking for palindromes from the centers, which is such a bright idea that it makes you go ":doh:! Why didn't I think of that?".
I leave it as an exercise for the reader to implement it in C - but it doesn't need any trees at all!