Cleanup after you are done is simple unless you are manually creating own structures. All what's needed is:
pANTLR3_INPUT_STREAM _input;
pMySQLLexer _lexer;
pANTLR3_COMMON_TOKEN_STREAM _tokens;
pMySQLParser _parser;
MySQLParser_query_return _ast;
_parser->free(_parser);
_tokens ->free(_tokens);
_lexer->free(_lexer);
_input->close(_input);
No need to free the tree in the stored ast, since the nodes are from a pool that gets freed when you free the parser.
For the invalid input: there must be something wrong in your error handler. ANTLR doesn't throw an exception if the input is wrong. See where the exception comes from. You are probably accessing an element that you think exist but doesn't.