Add support for freeing allocated structs

This means we can avoid memory leaks when using OSI