Update the valgrind cleanup code to handle most tri constructs