diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2021-09-03 12:46:17 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2021-09-03 13:23:50 +0300 |
commit | 3ac137811b090ce6db5a145b49a1588f267500cd (patch) | |
tree | b5b1d7922ad2230666fdf57b7c09be2f016d6fee | |
parent | b171cc6c59f377d28cd2afca76cb0d67162c7787 (diff) | |
download | gdbm-3ac137811b090ce6db5a145b49a1588f267500cd.tar.gz gdbm-3ac137811b090ce6db5a145b49a1588f267500cd.tar.bz2 |
gdbm_fuzzer: use atexit to free memory allocated for script buffer
* fuzz/gdbm_fuzzer.c: (fuzzer_exit): New function.
(LLVMFuzzerInitialize): Register atexit handler.
-rw-r--r-- | fuzz/gdbm_fuzzer.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/fuzz/gdbm_fuzzer.c b/fuzz/gdbm_fuzzer.c index 99db7cf..9067679 100644 --- a/fuzz/gdbm_fuzzer.c +++ b/fuzz/gdbm_fuzzer.c @@ -93,6 +93,15 @@ instream_string_create (char const *input, char const *name) static instream_t input; +void +fuzzer_exit (void) +{ + struct instream_string *istr = (struct instream_string *)input; + free (istr->string); + free (input->in_name); + free (input); +} + int LLVMFuzzerInitialize (int *argc, char ***argv) { @@ -139,9 +148,12 @@ LLVMFuzzerInitialize (int *argc, char ***argv) /* Set up the input stream */ input = instream_string_create (input_buffer, file_name); free (file_name); + free (input_buffer); if (!input) exit (1); + atexit (fuzzer_exit); + /* Disable usual gdbmshell output. */ stdout = fopen ("/dev/null","w"); if (!stdout) |