]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: event-filter - Handle allocations
authorAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 2 Jul 2020 06:55:31 +0000 (09:55 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 2 Jul 2020 06:55:31 +0000 (09:55 +0300)
This allows us to use Dovecot specific memory error handling
when allocations fail. Also squashes compiler warnings.

src/lib/event-filter-lexer.l

index 85e3994a34e405f2d03b9133c6254f8e127a5665..e80b79e663ce4dd419dee650a93a4e4ef8d6f926 100644 (file)
@@ -3,6 +3,7 @@
 %option nounput
 %option noinput
 %option noyywrap
+%option noyyalloc noyyrealloc noyyfree
 %option reentrant
 %option bison-bridge
 %option never-interactive
@@ -71,6 +72,31 @@ static size_t event_filter_parser_input_proc(char *buf, size_t size, yyscan_t sc
 #pragma clang diagnostic pop
 #endif
 
+void *yyalloc(size_t bytes, void* yyscanner ATTR_UNUSED)
+{
+       void *ptr = calloc(1, bytes);
+       if (ptr == NULL)
+               i_fatal_status(FATAL_OUTOFMEM, "calloc(1, %zu): Out of memory",
+                              bytes);
+       return ptr;
+}
+
+void *yyrealloc (void *ptr, size_t bytes, void *yyscanner ATTR_UNUSED)
+{
+       void *nptr = realloc(ptr, bytes);
+       if (nptr == NULL)
+               i_fatal_status(FATAL_OUTOFMEM, "realloc(ptr, %zu): Out of memory",
+                              bytes);
+       return nptr;
+}
+
+void yyfree(void *ptr, void *yyscanner ATTR_UNUSED)
+{
+       if (ptr == NULL)
+               return;
+       free(ptr);
+}
+
 static size_t event_filter_parser_input_proc(char *buf, size_t size, yyscan_t scanner)
 {
        struct event_filter_parser_state *state;