Memory leak fixes for the old-style gateway: