Fix some leaks and GCC 4.9.2 Compilation

Signed-off-by: TomorrowLandAce <joaolrpaulo@gmail.com>