Having had some trouble trying to use xmlListSort, I took a look at the implementation. It seems to work by copying the original list, clearing the original list, and then inserting each element from the copy into the original. Apart from inefficiency, this has one major bug: clearing the original list calls the user-supplied deallocator on each element, making those elements unusable in the copy. This resulted in accesses to freed memory, easily found via valgrind. - Josh Triplett