Skip to content

Commit

Permalink
Fix a crash bug when tokenizer has an error
Browse files Browse the repository at this point in the history
It's caused when tokenizer and token filter are registered and tokenizer
has an error.
  • Loading branch information
kou committed Jan 25, 2017
1 parent 0fb63dc commit ed9f59e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/token_cursor.c
@@ -1,6 +1,6 @@
/* -*- c-basic-offset: 2 -*- */
/*
Copyright(C) 2009-2014 Brazil
Copyright(C) 2009-2017 Brazil
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -39,7 +39,7 @@ grn_token_cursor_open_initialize_token_filters(grn_ctx *ctx,
return;
}

token_cursor->token_filter.data = GRN_MALLOCN(void *, n_token_filters);
token_cursor->token_filter.data = GRN_CALLOC(sizeof(void *) * n_token_filters);
if (!token_cursor->token_filter.data) {
return;
}
Expand Down Expand Up @@ -76,6 +76,7 @@ grn_token_cursor_open(grn_ctx *ctx, grn_obj *table,
token_cursor->encoding = encoding;
token_cursor->tokenizer = tokenizer;
token_cursor->token_filter.objects = token_filters;
token_cursor->token_filter.data = NULL;
token_cursor->orig = (const unsigned char *)str;
token_cursor->orig_blen = str_len;
token_cursor->curr = NULL;
Expand Down Expand Up @@ -341,6 +342,10 @@ grn_token_cursor_close_token_filters(grn_ctx *ctx,
grn_obj *token_filters = token_cursor->token_filter.objects;
unsigned int i, n_token_filters;

if (!token_cursor->token_filter.data) {
return;
}

if (token_filters) {
n_token_filters = GRN_BULK_VSIZE(token_filters) / sizeof(grn_obj *);
} else {
Expand Down

0 comments on commit ed9f59e

Please sign in to comment.