]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
coverity: fix memory leak in idnode_filter()
authorJaroslav Kysela <perex@perex.cz>
Fri, 3 Oct 2014 13:08:21 +0000 (15:08 +0200)
committerJaroslav Kysela <perex@perex.cz>
Fri, 3 Oct 2014 13:08:21 +0000 (15:08 +0200)
src/idnode.c

index 27b65e32ede576bba524a0569b317b92f973d823..6e5eac4c09b8d6fa3d6acf941fdf50296bdffc92 100644 (file)
@@ -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))