compiler/libec: Fixed various memory leaks and bugs