/* number of lines to allocate */
#define NALLOC 64
+#if defined(__SANITIZE_ADDRESS__) || defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
+# define COL_DEALLOCATE_ON_EXIT
+#endif
+
/* SI & SO charset mode */
enum {
CS_NORMAL,
uint8_t l_needs_sort:1; /* set if chars went in out of order */
};
-#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+#ifdef COL_DEALLOCATE_ON_EXIT
/*
* Free memory before exit when compiling LeakSanitizer.
*/
size_t max_bufd_lines; /* max # lines to keep in memory */
struct col_line *line_freelist;
size_t nblank_lines; /* # blanks after last flushed line */
-#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+#ifdef COL_DEALLOCATE_ON_EXIT
struct col_alloc *alloc_root; /* first of line allocations */
struct col_alloc *alloc_head; /* latest line allocation */
#endif
if (!ctl->line_freelist) {
l = xmalloc(sizeof(struct col_line) * NALLOC);
-#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+#ifdef COL_DEALLOCATE_ON_EXIT
if (ctl->alloc_root == NULL) {
ctl->alloc_root = xcalloc(1, sizeof(struct col_alloc));
ctl->alloc_root->l = l;
}
}
-#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+#ifdef COL_DEALLOCATE_ON_EXIT
static void free_line_allocations(struct col_alloc *root)
{
struct col_alloc *next;
for (; ctl.l->l_next; ctl.l = ctl.l->l_next)
lns.this_line++;
if (lns.max_line == 0 && lns.cur_col == 0) {
-#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+#ifdef COL_DEALLOCATE_ON_EXIT
free_line_allocations(ctl.alloc_root);
#endif
return EXIT_SUCCESS; /* no lines, so just exit */
/* missing a \n on the last line? */
ctl.nblank_lines = 2;
flush_blanks(&ctl);
-#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+#ifdef COL_DEALLOCATE_ON_EXIT
free_line_allocations(ctl.alloc_root);
#endif
return ret;