[Groonga-commit] groonga/groonga at d9823aa [master] pat_fuzzy: fix memory leak that prefix query isn't match any tokens

Back to archive index

Naoya Murakami null+****@clear*****
Sun Feb 11 23:04:39 JST 2018


Naoya Murakami	2018-02-11 23:04:39 +0900 (Sun, 11 Feb 2018)

  New Revision: d9823aa4b3794d3105dcb8f84e6cf711015aab09
  https://github.com/groonga/groonga/commit/d9823aa4b3794d3105dcb8f84e6cf711015aab09

  Merged db9782b: Merge pull request #820 from naoa/fix-memory-leak-fuzzy-search-prefix-no-match

  Message:
    pat_fuzzy: fix memory leak that prefix query isn't match any tokens

  Added files:
    test/command/suite/select/function/fuzzy_search/index/prefix.expected
    test/command/suite/select/function/fuzzy_search/index/prefix.test
    test/command/suite/select/function/fuzzy_search/index/prefix_no_match.expected
    test/command/suite/select/function/fuzzy_search/index/prefix_no_match.test
  Modified files:
    lib/pat.c

  Modified: lib/pat.c (+2 -0)
===================================================================
--- lib/pat.c    2018-02-09 13:12:45 +0900 (496549219)
+++ lib/pat.c    2018-02-11 23:04:39 +0900 (8cb17876f)
@@ -1556,6 +1556,7 @@ grn_pat_fuzzy_search(grn_ctx *ctx, grn_pat *pat,
     if (tid != GRN_ID_NIL) {
       id = tid;
     } else {
+      fuzzy_heap_close(ctx, heap);
       return GRN_END_OF_DATA;
     }
   }
@@ -1564,6 +1565,7 @@ grn_pat_fuzzy_search(grn_ctx *ctx, grn_pat *pat,
   }
   dists = GRN_MALLOC((lx + 1) * (lx + max_distance + 1) * sizeof(uint16_t));
   if (!dists) {
+    fuzzy_heap_close(ctx, heap);
     return GRN_NO_MEMORY_AVAILABLE;
   }
 

  Added: test/command/suite/select/function/fuzzy_search/index/prefix.expected (+53 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/fuzzy_search/index/prefix.expected    2018-02-11 23:04:39 +0900 (b59669f3a)
@@ -0,0 +1,53 @@
+table_create Users TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Users name COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+table_create Names TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Names user COLUMN_INDEX Users name
+[[0,0.0,0.0],true]
+load --table Users
+[
+{"name": "Tom"},
+{"name": "Tomy"},
+{"name": "Pom"},
+{"name": "Tom"}
+]
+[[0,0.0,0.0],4]
+select Users --filter 'fuzzy_search(name, "Tom", {"prefix_length": 1})'   --output_columns 'name, _score'   --match_escalation_threshold -1
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        3
+      ],
+      [
+        [
+          "name",
+          "ShortText"
+        ],
+        [
+          "_score",
+          "Int32"
+        ]
+      ],
+      [
+        "Tom",
+        2
+      ],
+      [
+        "Tomy",
+        1
+      ],
+      [
+        "Tom",
+        2
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/function/fuzzy_search/index/prefix.test (+17 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/fuzzy_search/index/prefix.test    2018-02-11 23:04:39 +0900 (80ca40077)
@@ -0,0 +1,17 @@
+table_create Users TABLE_NO_KEY
+column_create Users name COLUMN_SCALAR ShortText
+
+table_create Names TABLE_PAT_KEY ShortText
+column_create Names user COLUMN_INDEX Users name
+
+load --table Users
+[
+{"name": "Tom"},
+{"name": "Tomy"},
+{"name": "Pom"},
+{"name": "Tom"}
+]
+
+select Users --filter 'fuzzy_search(name, "Tom", {"prefix_length": 1})' \
+  --output_columns 'name, _score' \
+  --match_escalation_threshold -1

  Added: test/command/suite/select/function/fuzzy_search/index/prefix_no_match.expected (+18 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/fuzzy_search/index/prefix_no_match.expected    2018-02-11 23:04:39 +0900 (865e5ae48)
@@ -0,0 +1,18 @@
+table_create Users TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Users name COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+table_create Names TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Names user COLUMN_INDEX Users name
+[[0,0.0,0.0],true]
+load --table Users
+[
+{"name": "Tom"},
+{"name": "Tomy"},
+{"name": "Pom"},
+{"name": "Tom"}
+]
+[[0,0.0,0.0],4]
+select Users --filter 'fuzzy_search(name, "Atom", {"prefix_length": 1})'   --output_columns 'name, _score'   --match_escalation_threshold -1
+[[0,0.0,0.0],[[[0],[["name","ShortText"],["_score","Int32"]]]]]

  Added: test/command/suite/select/function/fuzzy_search/index/prefix_no_match.test (+17 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/fuzzy_search/index/prefix_no_match.test    2018-02-11 23:04:39 +0900 (87157cb0e)
@@ -0,0 +1,17 @@
+table_create Users TABLE_NO_KEY
+column_create Users name COLUMN_SCALAR ShortText
+
+table_create Names TABLE_PAT_KEY ShortText
+column_create Names user COLUMN_INDEX Users name
+
+load --table Users
+[
+{"name": "Tom"},
+{"name": "Tomy"},
+{"name": "Pom"},
+{"name": "Tom"}
+]
+
+select Users --filter 'fuzzy_search(name, "Atom", {"prefix_length": 1})' \
+  --output_columns 'name, _score' \
+  --match_escalation_threshold -1
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180211/8dfa8dae/attachment-0001.htm 



More information about the Groonga-commit mailing list
Back to archive index