Skip to content

Commit

Permalink
fix(memory): make sure codepoints will be allocated/freed after rb_ra…
Browse files Browse the repository at this point in the history
…ise to prevent memory leak

close #20
  • Loading branch information
tonytonyjan committed Aug 24, 2018
1 parent 5d38f8e commit fe9d784
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ext/jaro_winkler/jaro_winkler.c
Expand Up @@ -27,11 +27,8 @@ VALUE distance(size_t argc, VALUE *argv, VALUE self,
uint32_t *codepoints2, size_t len2,
Options *)) {
VALUE s1, s2, opt;
CodePoints cp1, cp2;

rb_scan_args((int32_t)argc, argv, "2:", &s1, &s2, &opt);
codepoints_init(&cp1, s1);
codepoints_init(&cp2, s2);

Options c_opt = DEFAULT_OPTIONS;
if (TYPE(opt) == T_HASH) {
Expand All @@ -54,6 +51,9 @@ VALUE distance(size_t argc, VALUE *argv, VALUE self,
c_opt.adj_table =
(TYPE(adj_table) == T_FALSE || NIL_P(adj_table)) ? 0 : 1;
}
CodePoints cp1, cp2;
codepoints_init(&cp1, s1);
codepoints_init(&cp2, s2);
VALUE ret = rb_float_new(
(*distance_fn)(cp1.data, cp1.length, cp2.data, cp2.length, &c_opt));
codepoints_free(&cp1);
Expand Down

0 comments on commit fe9d784

Please sign in to comment.