Clean up merge memleaks

Clean up memory leaks in header manipulation code