Free used constants if not used anymore

Fixes memleak
Fix unitialized value
Close file descriptors used for warnings and messages