remove memory leak in main.c

remove the memory leak and fix a variable set but never used