fix memory and resource leaks for non-fatal failure conditions
fix minor leak
check realloc return values
remove gear selector module (until it's done)