Index: commands.c
===================================================================
--- commands.c	(revision b31f1c9929b526b6d90b18b7847a024ff3d0c77d)
+++ commands.c	(revision 7013eb9642ccd31dfd15791df755d2f2152e0023)
@@ -2291,6 +2291,8 @@
   }
   filtname = owl_function_classinstfilt(argv[1], NULL, owl_global_is_narrow_related(&g));
-  owl_function_change_currentview_filter(filtname);
-  owl_free(filtname);
+  if (filtname) {
+    owl_function_change_currentview_filter(filtname);
+    owl_free(filtname);
+  }
   return NULL;
 }
@@ -2304,6 +2306,8 @@
   }
   filtname=owl_function_zuserfilt(argv[1]);
-  owl_function_change_currentview_filter(filtname);
-  owl_free(filtname);
+  if (filtname) {
+    owl_function_change_currentview_filter(filtname);
+    owl_free(filtname);
+  }
   return NULL;
 }
@@ -2395,5 +2399,5 @@
 char *owl_command_colorclass(int argc, const char *const *argv, const char *buff)
 {
-  const char *filtname;
+  char *filtname;
   
   if (argc < 3 || argc > 4) {
@@ -2403,5 +2407,8 @@
 
   filtname=owl_function_classinstfilt(argv[1], NULL, owl_global_is_narrow_related(&g));
-  (void) owl_function_color_filter(filtname, argv[2], (argc == 4 ? argv[3] : NULL));
+  if (filtname) {
+    (void) owl_function_color_filter(filtname, argv[2], (argc == 4 ? argv[3] : NULL));
+    owl_free(filtname);
+  }
   return NULL;
 }
Index: functions.c
===================================================================
--- functions.c	(revision f85278b8943b3c38ffc7ed08dfb9869f6cb7f1b9)
+++ functions.c	(revision 7013eb9642ccd31dfd15791df755d2f2152e0023)
@@ -2280,5 +2280,5 @@
 /* Create a filter for a class, instance if one doesn't exist.  If
  * instance is NULL then catch all messgaes in the class.  Returns the
- * name of the filter, which the caller must free.
+ * name of the filter or null.  The caller must free this name.
  * If 'related' is nonzero, encompass unclasses and .d classes as well.
  */
@@ -2348,9 +2348,16 @@
 
   f = owl_filter_new_fromstring(filtname, argbuff);
+  owl_free(argbuff);
+  if (f == NULL) {
+    /* Couldn't make a filter for some reason. Return NULL. */
+    owl_function_error("Error creating filter '%s'", filtname);
+    owl_free(filtname);
+    filtname = NULL;
+    goto done;
+  }
 
   /* add it to the global list */
   owl_global_add_filter(&g, f);
 
-  owl_free(argbuff);
 done:
   owl_free(class);
@@ -2390,13 +2397,18 @@
       "recipient ^%1$s$ ) ) ) or ( ( class ^login$ ) and ( sender ^%1$s$ ) )",
       esclonguser);
+  owl_free(esclonguser);
 
   f = owl_filter_new_fromstring(filtname, argbuff);
+  owl_free(argbuff);
+
+  if (f == NULL) {
+    /* Couldn't make a filter for some reason. Return NULL. */
+    owl_function_error("Error creating filter '%s'", filtname);
+    owl_free(filtname);
+    return NULL;
+  }
 
   /* add it to the global list */
   owl_global_add_filter(&g, f);
-
-  /* free stuff */
-  owl_free(argbuff);
-  owl_free(esclonguser);
 
   return(filtname);
@@ -2430,13 +2442,17 @@
       "( sender ^%2$s$ and recipient ^%1$s$ ) ) )",
       escuser, owl_global_get_aim_screenname_for_filters(&g));
+  owl_free(escuser);
 
   f = owl_filter_new_fromstring(filtname, argbuff);
+  owl_free(argbuff);
+
+  if (f == NULL) {
+    owl_function_error("Error creating filter '%s'", filtname);
+    owl_free(filtname);
+    return NULL;
+  }
 
   /* add it to the global list */
   owl_global_add_filter(&g, f);
-
-  /* free stuff */
-  owl_free(argbuff);
-  owl_free(escuser);
 
   return(filtname);
@@ -2460,13 +2476,17 @@
 
   argbuff = owl_sprintf("type ^%s$", esctype);
+  owl_free(esctype);
 
   f = owl_filter_new_fromstring(filtname, argbuff);
+  owl_free(argbuff);
+
+  if (f == NULL) {
+    owl_function_error("Error creating filter '%s'", filtname);
+    owl_free(filtname);
+    return NULL;
+  }
 
   /* add it to the global list */
   owl_global_add_filter(&g, f);
-
-  /* free stuff */
-  owl_free(argbuff);
-  owl_free(esctype);
 
   return filtname;
@@ -2520,4 +2540,10 @@
   f = owl_filter_new_fromstring(filtname, buf->str);
   g_string_free(buf, true);
+
+  if (f == NULL) {
+    owl_function_error("Error creating filter '%s'", filtname);
+    owl_free(filtname);
+    return NULL;
+  }
 
   owl_global_add_filter(&g, f);
