fix leaks
[m6w6/ext-psi] / src / parser_proc.c
index 6b8b81714bc991535ffc6e1b5526f3af2b476c6c..cb998f0ce3099f8afa95ec02c5eb83c043644a00 100644 (file)
@@ -9442,7 +9442,7 @@ static int psi_parser_proc_lex(YYSTYPE *lvalp, struct psi_parser *P, struct psi_
 #if PSI_DEBUG_LEX
        PSI_DEBUG_PRINT(P, "PSI: LEX index %4zu ", *index);
 #endif
 #if PSI_DEBUG_LEX
        PSI_DEBUG_PRINT(P, "PSI: LEX index %4zu ", *index);
 #endif
-       if (psi_plist_get(tokens, (*index)++, &token)) {
+       if (psi_plist_get(tokens, (*index)++, &token) && token) {
 #if PSI_DEBUG_LEX      
                PSI_DEBUG_DUMP(P, psi_token_dump, token);
 #endif
 #if PSI_DEBUG_LEX      
                PSI_DEBUG_DUMP(P, psi_token_dump, token);
 #endif
@@ -9475,11 +9475,22 @@ static void psi_parser_proc_error(struct psi_parser *P, struct psi_plist *tokens
                
                P->error(PSI_DATA(P), T, PSI_WARNING, "PSI %s at col %u", msg, T->col);
                while (i <= last || T->type != PSI_T_EOS) {
                
                P->error(PSI_DATA(P), T, PSI_WARNING, "PSI %s at col %u", msg, T->col);
                while (i <= last || T->type != PSI_T_EOS) {
+                       const char *pos;
+                       
                        if (!psi_plist_get(tokens, i++, &T)) {
                                break;
                        }
                        if (!psi_plist_get(tokens, i++, &T)) {
                                break;
                        }
+                       
+                       if (i < last + 1) {
+                               pos = "preceding";
+                       } else if (i > last + 1) {
+                               pos = "following";
+                       } else {
+                               pos = "offending";
+                       }
+                       
                        P->error(PSI_DATA(P), T, PSI_WARNING, "PSI %s token '%s' at col %u", 
                        P->error(PSI_DATA(P), T, PSI_WARNING, "PSI %s token '%s' at col %u", 
-                                       i<last+1?"preceding":i>last+1?"following":"offending", T->text->val, T->col);
+                                       pos, T ? T->text->val : "<deleted>", T ? T->col : 0);
                }
        } else {
                P->error(PSI_DATA(P), NULL, PSI_WARNING, "PSI %s", msg);
                }
        } else {
                P->error(PSI_DATA(P), NULL, PSI_WARNING, "PSI %s", msg);