Fix a memory leak and release all dynamically allocated memory (ivlpp)
This patch fixes a minor memory leak in ivlpp and releases all dynamically allocated memory before the program exits. Other than the dynamically allocated push state buffer in flex, ivlpp has no valgrind memory errors or warnings.
This commit is contained in:
parent
4c67bd0b35
commit
049290d0fc
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __globals_H
|
||||
#define __globals_H
|
||||
/*
|
||||
* Copyright (c) 1999-2007 Stephen Williams (steve@icarus.com)
|
||||
* Copyright (c) 1999-2008 Stephen Williams (steve@icarus.com)
|
||||
*
|
||||
* This source code is free software; you can redistribute it
|
||||
* and/or modify it in source code form under the terms of the GNU
|
||||
|
|
@ -25,6 +25,7 @@ extern void reset_lexor(FILE*out, char*paths[]);
|
|||
extern void load_precompiled_defines(FILE*src);
|
||||
extern void define_macro(const char*name, const char*value, int keyword,
|
||||
int argc);
|
||||
extern void free_macros();
|
||||
extern void dump_precompiled_defines(FILE*out);
|
||||
|
||||
/* These variables contain the include directories to be searched when
|
||||
|
|
|
|||
|
|
@ -833,6 +833,21 @@ void define_macro(const char* name, const char* value, int keyword, int argc)
|
|||
}
|
||||
}
|
||||
|
||||
static void free_macro(struct define_t* def)
|
||||
{
|
||||
if (def == 0) return;
|
||||
free_macro(def->left);
|
||||
free_macro(def->right);
|
||||
free(def->name);
|
||||
free(def->value);
|
||||
free(def);
|
||||
}
|
||||
|
||||
void free_macros()
|
||||
{
|
||||
free_macro(def_table);
|
||||
}
|
||||
|
||||
/*
|
||||
* The do_define function accumulates the defined value in these
|
||||
* variables. When the define is over, the def_finish() function
|
||||
|
|
@ -1462,6 +1477,8 @@ static void do_include()
|
|||
|
||||
if ((standby->file = fopen(path, "r")))
|
||||
{
|
||||
/* Free the original path before we overwrite it. */
|
||||
free(standby->path);
|
||||
standby->path = strdup(path);
|
||||
goto code_that_switches_buffers;
|
||||
}
|
||||
|
|
@ -1473,6 +1490,9 @@ static void do_include()
|
|||
|
||||
code_that_switches_buffers:
|
||||
|
||||
/* Clear the current files path from the search list. */
|
||||
include_dir[0] = 0;
|
||||
|
||||
if(depend_file)
|
||||
fprintf(depend_file, "%s\n", standby->path);
|
||||
|
||||
|
|
|
|||
14
ivlpp/main.c
14
ivlpp/main.c
|
|
@ -189,12 +189,14 @@ static int flist_read_names(const char*path)
|
|||
add_source_file(cp);
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char*argv[])
|
||||
{
|
||||
int opt, idx;
|
||||
unsigned lp;
|
||||
const char*flist_path = 0;
|
||||
unsigned flag_errors = 0;
|
||||
char*out_path = 0;
|
||||
|
|
@ -378,5 +380,17 @@ int main(int argc, char*argv[])
|
|||
fclose(precomp_out);
|
||||
}
|
||||
|
||||
/* Free the source and include directory lists. */
|
||||
for (lp = 0; lp < source_cnt; lp += 1) {
|
||||
free(source_list[lp]);
|
||||
}
|
||||
free(source_list);
|
||||
for (lp = 0; lp < include_cnt; lp += 1) {
|
||||
free(include_dir[lp]);
|
||||
}
|
||||
free(include_dir);
|
||||
|
||||
free_macros();
|
||||
|
||||
return error_count;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue