Fix compiler warnings and unfree'd mem on exit