Adapted and applied. I accidentally tagged the commit for #6202, which is a related issue (Sun patch for some of the same leaks). r20956 is the relevant commit.