remove memory leak on warnings when they are disabled

@yilongli please review