maint: separate PACIFY_LSAN from lint
In production there’s no need to free storage just before exiting. The freeing code might even have a bug and this would make the program less reliable. And it slows things down a bit, compared to just exiting. So, separate out PACIFY_LSAN (needed for ‘make build-asan’) from lint (needed when building with --enable-gcc-warnings). * cfg.mk (ASAN_CFLAGS): Define PACIFY_LSAN, not lint. * sed/compile.c (setup_replacement, finish_program): * sed/execute.c (process_files): * sed/regexp.c (release_regex): * sed/sed.c (cleanup, main): * sed/sed.h (struct subst): * sed/utils.c (panic): Use PACIFY_LSAN, not lint, to decide whether we are pacifying the leak sanitizer. * sed/sed.h (release_regex): Declare unconditionally, as there’s no harm declaring functions nobody calls or defines, and it’s even helpful to avoid inadvertent redefinition.
This commit is contained in:
1 parent
f25dea95fc
commit
308b851e4e
7 files changed
+19
-15
No files matched your search
@@ -369,7 +369,7 @@ static-analysis: static-analysis-init static-analysis-config \
|
||||
static-analysis-make
|
||||
|
||||
ASAN_FLAGS=-fsanitize=address -fno-omit-frame-pointer
|
||||
ASAN_CFLAGS=-O0 -g -Dlint $(ASAN_FLAGS)
|
||||
ASAN_CFLAGS=-O0 -g -DPACIFY_LSAN $(ASAN_FLAGS)
|
||||
ASAN_LDFLAGS=$(ASAN_FLAGS)
|
||||
|
||||
.PHONY: build-asan
|
||||
|
||||
+5
-3
@@ -658,7 +658,9 @@ setup_replacement (struct subst *sub, const char *text, idx_t length)
|
||||
base = xmemdup (text, length);
|
||||
length = normalize_text (base, length, TEXT_REPLACEMENT);
|
||||
|
||||
IF_LINT (sub->replacement_buffer = base);
|
||||
#ifdef PACIFY_LSAN
|
||||
sub->replacement_buffer = base;
|
||||
#endif
|
||||
|
||||
text_end = base + length;
|
||||
tail = &root;
|
||||
@@ -1562,7 +1564,7 @@ finish_program (struct vector *program)
|
||||
file_read = file_write = NULL;
|
||||
}
|
||||
|
||||
#ifdef lint
|
||||
#ifdef PACIFY_LSAN
|
||||
for (idx_t i = 0; i < program->v_length; ++i)
|
||||
{
|
||||
const struct sed_cmd *sc = &program->v[i];
|
||||
@@ -1585,6 +1587,6 @@ finish_program (struct vector *program)
|
||||
obstack_free (&obs, NULL);
|
||||
#else
|
||||
(void)program;
|
||||
#endif /* lint */
|
||||
#endif
|
||||
|
||||
}
|
||||
+2
-2
@@ -1599,7 +1599,7 @@ process_files (struct vector *the_program, char **argv)
|
||||
}
|
||||
closedown (&input);
|
||||
|
||||
#ifdef lint
|
||||
#ifdef PACIFY_LSAN
|
||||
/* We're about to exit, so these free()s are redundant.
|
||||
But if we're running under a memory-leak detecting
|
||||
implementation of malloc(), we want to explicitly
|
||||
@@ -1610,7 +1610,7 @@ process_files (struct vector *the_program, char **argv)
|
||||
free (hold.text);
|
||||
free (line.text);
|
||||
free (s_accum.text);
|
||||
#endif /* lint */
|
||||
#endif
|
||||
|
||||
if (input.bad_count)
|
||||
status = EXIT_BAD_INPUT;
|
||||
|
||||
+2
-2
@@ -347,7 +347,7 @@ match_regex (struct regex *regex, char *buf, idx_t buflen,
|
||||
}
|
||||
|
||||
|
||||
#ifdef lint
|
||||
#ifdef PACIFY_LSAN
|
||||
void
|
||||
release_regex (struct regex *regex)
|
||||
{
|
||||
@@ -360,4 +360,4 @@ release_regex (struct regex *regex)
|
||||
regfree (®ex->pattern);
|
||||
free (regex);
|
||||
}
|
||||
#endif /* lint */
|
||||
#endif
|
||||
@@ -91,7 +91,9 @@ struct localeinfo localeinfo;
|
||||
static void
|
||||
cleanup (void)
|
||||
{
|
||||
IF_LINT (free (in_place_extension));
|
||||
#ifdef PACIFY_LSAN
|
||||
free (in_place_extension);
|
||||
#endif
|
||||
remove_cleanup_file ();
|
||||
}
|
||||
|
||||
@@ -280,7 +282,9 @@ main (int argc, char **argv)
|
||||
|
||||
case 'i':
|
||||
separate_files = true;
|
||||
IF_LINT (free (in_place_extension));
|
||||
#ifdef PACIFY_LSAN
|
||||
free (in_place_extension);
|
||||
#endif
|
||||
if (optarg == NULL)
|
||||
/* use no backups */
|
||||
in_place_extension = xstrdup ("*");
|
||||
|
||||
@@ -139,8 +139,8 @@ struct subst {
|
||||
unsigned print : 2; /* 'p' option given (before/after eval) */
|
||||
unsigned eval : 1; /* 'e' option given */
|
||||
unsigned max_id : 4; /* maximum backreference on the RHS */
|
||||
#ifdef lint
|
||||
char* replacement_buffer;
|
||||
#ifdef PACIFY_LSAN
|
||||
char *replacement_buffer;
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -236,9 +236,7 @@ struct regex *compile_regex (struct buffer *b, int flags, int needed_sub);
|
||||
int match_regex (struct regex *regex,
|
||||
char *buf, idx_t buflen, idx_t buf_start_offset,
|
||||
struct re_registers *regarray, int regsize);
|
||||
#ifdef lint
|
||||
void release_regex (struct regex *);
|
||||
#endif
|
||||
|
||||
void
|
||||
debug_print_command (const struct vector *program, const struct sed_cmd *sc);
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ panic (const char *str, ...)
|
||||
va_end (ap);
|
||||
putc ('\n', stderr);
|
||||
|
||||
#ifdef lint
|
||||
#ifdef PACIFY_LSAN
|
||||
while (open_files)
|
||||
{
|
||||
struct open_file *next = open_files->link;
|
||||
|
||||
Reference in new issue
Block a user