A bug fix and small code improvements?

I have fixed a bug (which won't show up if TRI_Allocate() doesn't fail allocating memory) and have done some small code improvements? (just take the bits you consider correct and useful).