The attached patch addresses some of the memory leaks in the perl module when using unsafe module functions.
The advantage is that it fixes leaks in some of the more commonly used functions (sl_send_reply, insert_hf, remove_hf, t_reply). The disadvantage is that it doesn't fix all of the leaks in all of the module functions, which gives people a slightly false sense of security. However, if people are using the unsafemodfnc parameter, presumably they understand some of the risks. It should be pretty easy to extend this solution, so anyone who wants to make their own modifications on a local build can fix memory leaks in the future.
I've been using a similar patch in production use, on hundreds of thousands of calls per day, and it seems to work well for my particular case, so I'm submitting it upstream for consideration. On the other hand, the solution is something of a hack. I totally understand not wanting to accept a patch that doesn't provide a general case solution.