Skip to content

Commit

Permalink
Filter(fix): fix pattern filter memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverRainZ committed Sep 5, 2019
1 parent c715c62 commit 9464a9e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/filter/pattern_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void finalize(void) {
}

static bool filter(const SrnMessage *msg) {
bool drop;
char *raw_content;
GList *patterns;
GList *lst;
Expand All @@ -74,10 +75,11 @@ static bool filter(const SrnMessage *msg) {
ret = srn_markup_renderer_render(markup_renderer,
msg->rendered_content, &raw_content, NULL);
if (!RET_IS_OK(ret)){
// ret = RET_ERR(_("Failed to render markup text: %1$s"), RET_MSG(ret));
// return TRUE;
ERR_FR("Failed to render markup text: %1$s", RET_MSG(ret));
return TRUE;
}

drop = FALSE;
patterns = get_patterns(msg);
lst = patterns;
while (lst) {
Expand All @@ -86,18 +88,17 @@ static bool filter(const SrnMessage *msg) {

pattern = lst->data;
regex = srn_pattern_set_get(pattern_set, pattern);
if (regex) {
if (g_regex_match(regex, raw_content, 0, NULL)) {
return FALSE;
}
if (regex && g_regex_match(regex, raw_content, 0, NULL)) {
drop = TRUE;
break;
}
lst = g_list_next(lst);
}

g_list_free(patterns);
g_free(raw_content);

// TODO
return TRUE;
return !drop;
}

/**
Expand Down

0 comments on commit 9464a9e

Please sign in to comment.