Code

utils_vl_lookup: Free regexen when destroying class lists.
authorSebastian Harl <sh@tokkee.org>
Sat, 4 Jun 2016 15:58:23 +0000 (17:58 +0200)
committerSebastian Harl <sh@tokkee.org>
Sat, 4 Jun 2016 16:30:49 +0000 (18:30 +0200)
Else, we'll leak any memory used by the regex.

src/utils_vl_lookup.c

index a0237841eb43a7aebea172bed7246cd71f0e0bea..8a2e5671110f196e9ba72166303d9fbd436826b9 100644 (file)
@@ -495,6 +495,21 @@ static void lu_destroy_user_class_list (lookup_t *obj, /* {{{ */
       obj->cb_free_class (user_class_list->entry.user_class);
     user_class_list->entry.user_class = NULL;
 
+#define CLEAR_FIELD(field) do { \
+    if (user_class_list->entry.match.field.is_regex) { \
+      regfree (&user_class_list->entry.match.field.regex); \
+      user_class_list->entry.match.field.is_regex = 0; \
+    } \
+} while (0)
+
+    CLEAR_FIELD (host);
+    CLEAR_FIELD (plugin);
+    CLEAR_FIELD (plugin_instance);
+    CLEAR_FIELD (type);
+    CLEAR_FIELD (type_instance);
+
+#undef CLEAR_FIELD
+
     lu_destroy_user_obj (obj, user_class_list->entry.user_obj_list);
     user_class_list->entry.user_obj_list = NULL;
     pthread_mutex_destroy (&user_class_list->entry.lock);