Fix memory leaks in vvp and change vvp T_STRING token to be new based.

This patch fixes a bunch of memory leaks in vvp and converts the
T_STRING lexical token to be new based. There are still two
known leaks that I need to find a way to fix and likely some
unknown leaks that still need to be found and fixed.
This commit is contained in:
Cary R 2009-01-13 09:57:12 -08:00 committed by Stephen Williams
parent 8ca3ea2e83
commit c2605a5c9b
14 changed files with 68 additions and 56 deletions

View File

@ -2213,6 +2213,7 @@ static PLI_INT32 sys_fdisplay_calltf(PLI_BYTE8*name)
vpi_printf("invalid file descriptor/MCD (0x%x) given to %s.\n",
fd_mcd, name);
vpi_control(vpiFinish, 1);
vpi_free_object(argv);
return 0;
}
@ -2309,6 +2310,7 @@ static PLI_INT32 sys_swrite_calltf(PLI_BYTE8 *name)
"(see %%u/%%z).\n", info.filename, info.lineno, name);
}
free(val.value.str);
free(info.filename);
free(info.items);
return 0;
@ -2406,6 +2408,7 @@ static PLI_INT32 sys_sformat_calltf(PLI_BYTE8 *name)
"(see %%u/%%z).\n", info.filename, info.lineno, name);
}
free(val.value.str);
free(info.filename);
free(info.items);
return 0;
@ -2415,6 +2418,7 @@ static PLI_INT32 sys_end_of_compile(p_cb_data cb_data)
{
/* The default timeformat prints times in unit of simulation
precision. */
free(timeformat_info.suff);
timeformat_info.suff = strdup("");
timeformat_info.units = vpi_get(vpiTimePrecision, 0);
timeformat_info.prec = 0;
@ -2481,6 +2485,7 @@ static PLI_INT32 sys_timeformat_calltf(PLI_BYTE8*xx)
value.format = vpiStringVal;
vpi_get_value(suff, &value);
free(timeformat_info.suff);
timeformat_info.suff = strdup(value.value.str);
value.format = vpiIntVal;
@ -2553,6 +2558,7 @@ static PLI_INT32 sys_no_aa_compiletf(PLI_BYTE8 *name)
vpi_printf("%s arguments may not be automatically "
"allocated variables.\n", name);
vpi_control(vpiFinish, 1);
vpi_free_object(argv);
return 0;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000-2003 Stephen Williams (steve@icarus.com)
* Copyright (c) 2000-2009 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
@ -645,6 +645,7 @@ static PLI_INT32 sys_urandom_range_calltf(PLI_BYTE8 *name)
/* Calculate and return the result. */
val.value.integer = urandom(0, i_maxval, i_minval);
vpi_put_value(callh, &val, 0, vpiNoDelay);
vpi_free_object(argv);
return 0;
}
@ -978,4 +979,3 @@ void sys_random_register()
tf_data.user_data = "$dist_erlang";
vpi_register_systf(&tf_data);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999 Stephen Williams (steve@icarus.com)
* Copyright (c) 1999-2009 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
@ -412,6 +412,7 @@ static PLI_INT32 sys_writemem_calltf(PLI_BYTE8*name)
start_item = vpi_scan(argv);
if (start_item!=0){
if (check_integer_constant(name, start_item) == 0){
free(path);
vpi_free_object(argv);
return 0;
}
@ -420,6 +421,7 @@ static PLI_INT32 sys_writemem_calltf(PLI_BYTE8*name)
stop_item = vpi_scan(argv);
if (stop_item!=0){
if (check_integer_constant(name, stop_item) == 0){
free(path);
vpi_free_object(argv);
return 0;
}
@ -427,6 +429,7 @@ static PLI_INT32 sys_writemem_calltf(PLI_BYTE8*name)
/* Check that there is no 5th parameter */
if (vpi_scan(argv) != 0){
vpi_printf("ERROR: %s accepts maximum 4 parameters!\n", name );
free(path);
vpi_free_object(argv);
return 0;
}
@ -519,6 +522,7 @@ static PLI_INT32 sys_writemem_calltf(PLI_BYTE8*name)
item = vpi_scan(words);
wwid = vpi_get(vpiSize, item);
vpi_free_object(words);
if (strcmp(name,"$writememb")==0){
value.format = vpiBinStrVal;
@ -541,6 +545,7 @@ static PLI_INT32 sys_writemem_calltf(PLI_BYTE8*name)
}
fclose(file);
free(path);
return 0;
}
@ -580,4 +585,3 @@ void sys_readmem_register()
tf_data.user_data = "$writememb";
vpi_register_systf(&tf_data);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999-2008 Stephen Williams (steve@icarus.com)
* Copyright (c) 1999-2009 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
@ -428,6 +428,7 @@ static PLI_INT32 sys_dumpfile_calltf(PLI_BYTE8*name)
vpi_printf("VCD warning: %s called after $dumpvars started,\n"
" using existing file (%s).\n",
name, dump_path);
vpi_free_object(argv);
return 0;
}
@ -698,10 +699,16 @@ static PLI_INT32 sys_dumpvars_calltf(PLI_BYTE8*name)
if (dump_file == 0) {
open_dumpfile(callh);
if (dump_file == 0) return 0;
if (dump_file == 0) {
vpi_free_object(argv);
return 0;
}
}
if (install_dumpvars_callback()) return 0;
if (install_dumpvars_callback()) {
vpi_free_object(argv);
return 0;
}
/* Get the depth if it exists. */
if (argv) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007-2008 Stephen Williams (steve@icarus.com)
* Copyright (c) 2007-2009 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
@ -938,7 +938,7 @@ void compile_var_array(char*label, char*name, int last, int first,
count_var_array_words += arr->array_count;
free(label);
free(name);
delete[] name;
}
void compile_real_array(char*label, char*name, int last, int first,
@ -962,7 +962,7 @@ void compile_real_array(char*label, char*name, int last, int first,
count_real_array_words += arr->array_count;
free(label);
free(name);
delete[] name;
}
void compile_net_array(char*label, char*name, int last, int first)
@ -976,7 +976,7 @@ void compile_net_array(char*label, char*name, int last, int first)
count_net_array_words += arr->array_count;
free(label);
free(name);
delete[] name;
}
class vvp_fun_arrayport : public vvp_net_fun_t {

View File

@ -704,7 +704,7 @@ void compile_init(void)
void compile_load_vpi_module(char*name)
{
vpip_load_module(name);
free(name);
delete[] name;
}
void compile_vpi_time_precision(long pre)
@ -1710,7 +1710,7 @@ void compile_vpi_call(char*label, char*name,
compile_errors += 1;
/* Done with the lexor-allocated name string. */
free(name);
delete[] name;
}
void compile_vpi_func_call(char*label, char*name,
@ -1733,7 +1733,7 @@ void compile_vpi_func_call(char*label, char*name,
compile_errors += 1;
/* Done with the lexor-allocated name string. */
free(name);
delete[] name;
}
/*

View File

@ -1,7 +1,7 @@
#ifndef __compile_H
#define __compile_H
/*
* Copyright (c) 2001-2008 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-2009 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
@ -412,7 +412,7 @@ extern void compile_codelabel(char*label);
* The parser uses these functions to compile .scope statements.
* The implementations of these live in the vpi_scope.cc file.
*/
extern void compile_scope_decl(char*typ, char*lab, char*nam,const char*tnam,
extern void compile_scope_decl(char*typ, char*lab, char*nam, char*tnam,
char*par, long file_idx, long lineno,
long def_file_idx, long def_lineno);
extern void compile_scope_recall(char*sym);
@ -472,5 +472,4 @@ extern void compile_island_tranif(int sense, char*island,
extern void compile_island_tranvp(char*island, char*ba, char*bb,
unsigned width, unsigned part, unsigned off);
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004-2005 Stephen Williams (steve@icarus.com)
* Copyright (c) 2004-2009 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
@ -80,6 +80,7 @@ void compile_concat(char*label, unsigned w0, unsigned w1,
free(label);
inputs_connect(net, argc, argv);
free(argv);
}
vvp_fun_repeat::vvp_fun_repeat(unsigned width, unsigned repeat)
@ -121,23 +122,3 @@ void compile_repeat(char*label, long width, long repeat, struct symb_s arg)
input_connect(net, 0, arg.text);
}
/*
* $Log: concat.cc,v $
* Revision 1.5 2005/06/22 00:04:48 steve
* Reduce vvp_vector4 copies by using const references.
*
* Revision 1.4 2005/06/17 03:46:52 steve
* Make functors know their own width.
*
* Revision 1.3 2005/04/09 05:30:38 steve
* Default behavior for recv_vec8 methods.
*
* Revision 1.2 2005/02/07 22:42:42 steve
* Add .repeat functor and BIFIF functors.
*
* Revision 1.1 2005/01/22 00:01:09 steve
* Add missing concat.cc to cvs
*
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004-2008 Stephen Williams (steve@icarus.com)
* Copyright (c) 2004-2009 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
@ -695,6 +695,7 @@ void compile_event(char*label, char*type, unsigned argc, struct symb_s*argv)
free(label);
inputs_connect(ptr, argc, argv);
free(argv);
}
static void compile_event_or(char*label, unsigned argc, struct symb_s*argv)
@ -714,6 +715,7 @@ static void compile_event_or(char*label, unsigned argc, struct symb_s*argv)
for (unsigned idx = 0 ; idx < argc ; idx += 1) {
input_connect(ptr, 0, argv[idx].text);
}
free(argv);
}
/*
@ -737,5 +739,5 @@ void compile_named_event(char*label, char*name)
vpip_attach_to_current_scope(obj);
free(label);
free(name);
delete[] name;
}

View File

@ -4,7 +4,7 @@
%{
/*
* Copyright (c) 2001-2008 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-2009 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
@ -27,6 +27,11 @@
# include "parse.h"
# include <string.h>
# include <assert.h>
static char* strdupnew(char const *str)
{
return str ? strcpy(new char [strlen(str)+1], str) : 0;
}
%}
%%
@ -48,7 +53,7 @@
contents of the string without the enclosing quotes. */
\"([^\"\\]|\\.)*\" {
yytext[strlen(yytext)-1] = 0;
yylval.text = strdup(yytext+1);
yylval.text = strdupnew(yytext+1);
assert(yylval.text);
return T_STRING; }

View File

@ -146,7 +146,7 @@ void verify_version(char*ivl_ver, char*commit)
if (commit) vpi_mcd_printf(1, " %s", commit);
vpi_mcd_printf(1, "\n");
}
free(commit);
delete[] commit;
char*vvp_ver = strdup(VERSION);
char *vp, *ip;
@ -186,7 +186,7 @@ void verify_version(char*ivl_ver, char*commit)
ip, vp);
}
free(ivl_ver);
delete[] ivl_ver;
free(vvp_ver);
}
@ -418,5 +418,11 @@ int main(int argc, char*argv[])
count_gen_events, count_gen_pool());
}
/* Clean up the memory. */
for (vector<const char*>::iterator cur = file_names.begin();
cur != file_names.end() ; cur++) {
delete[] *cur;
}
return vvp_return_value;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2008 Stephen Williams (steve@icarus.com)
* Copyright (c) 2006-2009 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
@ -145,7 +145,7 @@ void compile_sfunc(char*label, char*name, char*format_string,
{
vpiHandle*vpi_argv = new vpiHandle[argc];
int width_code = make_vpi_argv(argc, vpi_argv, format_string);
free(format_string);
delete[] format_string;
vvp_net_t*ptr = new vvp_net_t;
@ -167,4 +167,5 @@ void compile_sfunc(char*label, char*name, char*format_string,
that event. */
if (trigger_label)
input_connect(ptr, 0, trigger_label);
delete[] name;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001-2008 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-2009 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
@ -326,7 +326,7 @@ static void attach_to_scope_(struct __vpiScope*scope, vpiHandle obj)
* symbol table and the name is used to construct the actual object.
*/
void
compile_scope_decl(char*label, char*type, char*name, const char*tname,
compile_scope_decl(char*label, char*type, char*name, char*tname,
char*parent, long file_idx, long lineno,
long def_file_idx, long def_lineno)
{
@ -381,7 +381,8 @@ compile_scope_decl(char*label, char*type, char*name, const char*tname,
free(label);
free(type);
free(name);
delete[] name;
delete[] tname;
if (parent) {
static vpiHandle obj;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2008 Stephen Williams (steve@icarus.com)
* Copyright (c) 2003-2009 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
@ -59,7 +59,7 @@ static void __compile_var_real(char*label, char*name,
array_attach_word(array, array_addr, obj);
}
free(label);
if (name) free(name);
if (name) delete[] name;
}
void compile_var_real(char*label, char*name, int msb, int lsb)
@ -118,7 +118,7 @@ static void __compile_var(char*label, char*name,
if (obj) array_attach_word(array, array_addr, obj);
}
free(label);
if (name) free(name);
if (name) delete[] name;
}
void compile_variable(char*label, char*name,
@ -194,7 +194,7 @@ static void __compile_net(char*label, char*name,
vpip_attach_to_current_scope(obj);
free(label);
if (name) free(name);
if (name) delete[] name;
if (array_label) free(array_label);
free(argv);
}
@ -254,7 +254,7 @@ static void __compile_real(char*label, char*name,
else if (obj)
vpip_attach_to_current_scope(obj);
free(label);
if (name) free(name);
if (name) delete[] name;
if (array_label) free(array_label);
free(argv);
}
@ -313,7 +313,7 @@ void compile_alias(char*label, char*name, int msb, int lsb, bool signed_flag,
vpip_attach_to_current_scope(obj);
free(label);
free(name);
delete[] name;
free(argv[0].text);
free(argv);
}
@ -335,7 +335,7 @@ void compile_alias_real(char*label, char*name, int msb, int lsb,
vpip_attach_to_current_scope(obj);
free(label);
free(name);
delete[] name;
free(argv[0].text);
free(argv);
}