CCL: fix leak on syntax errors with split-list
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 8 Jun 2015 12:58:17 +0000 (14:58 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 8 Jun 2015 12:58:17 +0000 (14:58 +0200)
src/cclfind.c
test/test_ccl.c

index 9403634..0ef140b 100644 (file)
@@ -648,7 +648,10 @@ static struct ccl_rpn_node *split_recur(CCL_parser cclp, ccl_qualifier_t *qa,
                                                      l > 1,
                                                      /* auto_group */0);
         if (!p2)
+        {
+            ccl_rpn_delete(p_top);
             return 0;
+        }
         if (parent)
         {
             struct ccl_rpn_node *tmp = ccl_rpn_node_create(CCL_RPN_AND);
@@ -660,6 +663,12 @@ static struct ccl_rpn_node *split_recur(CCL_parser cclp, ccl_qualifier_t *qa,
             p1 = split_recur(cclp, qa, p2, ar + l, sz - l);
         else
             p1 = p2;
+        if (!p1)
+        {
+            ccl_rpn_delete(p2);
+            ccl_rpn_delete(p_top);
+            return 0;
+        }
         p_top = ccl_rpn_node_mkbool(p_top, p1, CCL_RPN_OR);
     }
     assert(p_top);
index 2cfc545..5fdb954 100644 (file)
@@ -463,6 +463,9 @@ void tst1(int pass)
                             "@or @attr 1=2 b @attr 1=3 b "
                             "@or @attr 1=2 \"a b\" @attr 1=3 \"a b\" "));
 
+    YAZ_CHECK(tst_ccl_query(bibset, "s2=a? b", 0));
+    YAZ_CHECK(tst_ccl_query(bibset, "s2=a b?", 0));
+    YAZ_CHECK(tst_ccl_query(bibset, "s2=a b? c", 0));
 
     ccl_qual_rm(&bibset);
 }