Cleaned up the regexp de-allocation + syntax check for --delete-regexp.
authorFrancois Fleuret <francois@fleuret.org>
Tue, 8 Oct 2019 05:38:59 +0000 (07:38 +0200)
committerFrancois Fleuret <francois@fleuret.org>
Tue, 8 Oct 2019 05:38:59 +0000 (07:38 +0200)
selector.c

index f573d79..4f4c0bc 100644 (file)
@@ -1126,7 +1126,11 @@ int main(int argc, char **argv) {
     case OPT_DELETE_REGEXP:
       free(global_prefix_regexp);
       global_prefix_regexp = safe_malloc(sizeof(*global_prefix_regexp));
-      regcomp(global_prefix_regexp, optarg, 0);
+
+      if(regcomp(global_prefix_regexp, optarg, 0)) {
+        fprintf(stderr, "selector: Regexp syntax error `%s'.\n", optarg);
+        exit(EXIT_FAILURE);
+      }
       break;
 
     case 'r':
@@ -1463,7 +1467,11 @@ int main(int argc, char **argv) {
   free(labels);
   free(lines);
   free(global_title);
-  free(global_prefix_regexp);
+
+  if(global_prefix_regexp) {
+    regfree(global_prefix_regexp);
+    free(global_prefix_regexp);
+  }
 
   exit(EXIT_SUCCESS);
 }