From 5fff5d40bc265a4f1dbabec977ecb63d0ecbe822 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Fri, 3 Oct 2014 15:08:21 +0200 Subject: [PATCH] coverity: fix memory leak in idnode_filter() --- src/idnode.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/idnode.c b/src/idnode.c index 27b65e32..6e5eac4c 100644 --- a/src/idnode.c +++ b/src/idnode.c @@ -780,31 +780,22 @@ idnode_filter idnode_filter_init(in, filter); if (f->type == IF_STR) { const char *str; - str = idnode_get_display(in, idnode_find_prop(in, f->key)); + char *strdisp; + int r = 1; + str = strdisp = idnode_get_display(in, idnode_find_prop(in, f->key)); if (!str) if (!(str = idnode_get_str(in, f->key))) return 1; switch(f->comp) { - case IC_IN: - if (strstr(str, f->u.s) == NULL) - return 1; - break; - case IC_EQ: - if (strcmp(str, f->u.s) != 0) - return 1; - case IC_LT: - if (strcmp(str, f->u.s) > 0) - return 1; - break; - case IC_GT: - if (strcmp(str, f->u.s) < 0) - return 1; - break; - case IC_RE: - if (regexec(&f->u.re, str, 0, NULL, 0)) - return 1; - break; + case IC_IN: r = strstr(str, f->u.s) == NULL; break; + case IC_EQ: r = strcmp(str, f->u.s) != 0; break; + case IC_LT: r = strcmp(str, f->u.s) > 0; break; + case IC_GT: r = strcmp(str, f->u.s) < 0; break; + case IC_RE: r = !!regexec(&f->u.re, str, 0, NULL, 0); break; } + if (strdisp) + free(strdisp); + return r; } else if (f->type == IF_NUM || f->type == IF_BOOL) { int64_t a, b; if (idnode_get_s64(in, f->key, &a))