diff --git a/src/fd.c b/src/fd.c index 6258d16..e48c759 100644 --- a/src/fd.c +++ b/src/fd.c @@ -45,7 +45,7 @@ static int has_include = 0, has_exclude = 0; /* File descriptor cherry picking */ static int *ranges = NULL; -static int ranges_static[512]; +static int static_ranges[512]; /* File descriptor stuff. When program is launched, we use the static array of * 32 structures, which ought to be enough for most programs. If it happens @@ -98,8 +98,7 @@ void _zz_exclude(char const *regex) /* This function is the same as _zz_bytes() */ void _zz_pick(char const *list) { - /* TODO: free(ranges) if ranges != ranges_static */ - ranges = _zz_allocrange(list, ranges_static); + ranges = _zz_allocrange(list, static_ranges); } void _zz_setseed(int32_t s) @@ -190,6 +189,8 @@ void _zz_fd_fini(void) free(files); if(fds != static_fds) free(fds); + if(ranges != static_ranges) + free(ranges); } int _zz_mustwatch(char const *file) diff --git a/src/fuzz.c b/src/fuzz.c index dc73af3..812746f 100644 --- a/src/fuzz.c +++ b/src/fuzz.c @@ -46,7 +46,7 @@ fuzzing; /* Per-offset byte protection */ static int *ranges = NULL; -static int ranges_static[512]; +static int static_ranges[512]; /* Per-value byte protection */ static int protect[256]; @@ -68,8 +68,8 @@ extern void _zz_fuzzing(char const *mode) /* This function is the same as _zz_pick() */ void _zz_bytes(char const *list) { - /* TODO: free(ranges) if ranges != ranges_static */ - ranges = _zz_allocrange(list, ranges_static); + /* TODO: free(ranges) if ranges != static_ranges */ + ranges = _zz_allocrange(list, static_ranges); } void _zz_protect(char const *list) diff --git a/src/ranges.c b/src/ranges.c index ef706ec..6c56acf 100644 --- a/src/ranges.c +++ b/src/ranges.c @@ -32,9 +32,9 @@ /* This function converts a string containing a list of ranges in the format * understood by cut(1) such as "1-5,8,10-" into a C array for lookup. * If more than 256 slots are required, new memory is allocated, otherwise - * the static array ranges_static is used. It is the caller's duty to call - * free() if the returned value is not ranges_static. */ -int *_zz_allocrange(char const *list, int *ranges_static) + * the static array static_ranges is used. It is the caller's duty to call + * free() if the returned value is not static_ranges. */ +int *_zz_allocrange(char const *list, int *static_ranges) { char const *parser; int *ranges; @@ -48,7 +48,7 @@ int *_zz_allocrange(char const *list, int *ranges_static) if(chunks >= 256) ranges = malloc((chunks + 1) * 2 * sizeof(unsigned int)); else - ranges = ranges_static; + ranges = static_ranges; /* Fill ranges list */ for(parser = list, i = 0; i < chunks; i++)