Fix some memory leaks/issues found with cppcheck.
I ran cppcheck on the code and it found a few obscure memory leaks and a few other issues. This patch fixes most of them.
This commit is contained in:
parent
ce89a68735
commit
2e166b7279
4
Attrib.h
4
Attrib.h
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __Attrib_H
|
||||
#define __Attrib_H
|
||||
/*
|
||||
* Copyright (c) 2000 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
|
||||
|
|
@ -30,7 +30,7 @@ class Attrib {
|
|||
|
||||
public:
|
||||
Attrib();
|
||||
~Attrib();
|
||||
virtual ~Attrib();
|
||||
|
||||
const verinum&attribute(perm_string key) const;
|
||||
void attribute(perm_string key, const verinum&value);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __LineInfo_H
|
||||
#define __LineInfo_H
|
||||
/*
|
||||
* 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
|
||||
|
|
@ -36,7 +36,7 @@ using namespace std;
|
|||
class LineInfo {
|
||||
public:
|
||||
LineInfo();
|
||||
~LineInfo();
|
||||
virtual ~LineInfo();
|
||||
|
||||
// Get a fully formatted file/lineno
|
||||
string get_fileline() const;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* VHDL code generation for expressions.
|
||||
*
|
||||
* Copyright (C) 2008 Nick Gasson (nick@nickg.me.uk)
|
||||
* Copyright (C) 2008-2009 Nick Gasson (nick@nickg.me.uk)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -107,8 +107,10 @@ static vhdl_var_ref *translate_signal(ivl_expr_t e)
|
|||
if (ivl_signal_array_count(sig) > 0 && (off = ivl_expr_oper1(e))) {
|
||||
// Select from an array
|
||||
vhdl_expr *vhd_off = translate_expr(off);
|
||||
if (NULL == vhd_off)
|
||||
if (NULL == vhd_off) {
|
||||
delete ref;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vhdl_type integer(VHDL_TYPE_INTEGER);
|
||||
ref->set_slice(vhd_off->cast(&integer));
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* VHDL code generation for LPM devices.
|
||||
*
|
||||
* Copyright (C) 2008 Nick Gasson (nick@nickg.me.uk)
|
||||
* Copyright (C) 2008-2009 Nick Gasson (nick@nickg.me.uk)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -50,8 +50,10 @@ static vhdl_expr *concat_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm)
|
|||
|
||||
for (int i = ivl_lpm_selects(lpm) - 1; i >= 0; i--) {
|
||||
vhdl_expr *e = readable_ref(scope, ivl_lpm_data(lpm, i));
|
||||
if (NULL == e)
|
||||
if (NULL == e) {
|
||||
delete expr;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
expr->add_expr(e);
|
||||
}
|
||||
|
|
@ -68,8 +70,10 @@ static vhdl_expr *binop_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm, vhdl_binop
|
|||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
vhdl_expr *e = readable_ref(scope, ivl_lpm_data(lpm, i));
|
||||
if (NULL == e)
|
||||
if (NULL == e) {
|
||||
delete expr;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
expr->add_expr(e->cast(result_type));
|
||||
}
|
||||
|
|
@ -95,8 +99,10 @@ static vhdl_expr *rel_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm, vhdl_binop_t
|
|||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
vhdl_expr *e = readable_ref(scope, ivl_lpm_data(lpm, i));
|
||||
if (NULL == e)
|
||||
if (NULL == e) {
|
||||
delete expr;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
expr->add_expr(e);
|
||||
}
|
||||
|
|
@ -135,8 +141,10 @@ static vhdl_expr *ufunc_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm)
|
|||
|
||||
for (unsigned i = 0; i < ivl_lpm_size(lpm); i++) {
|
||||
vhdl_var_ref *ref = readable_ref(scope, ivl_lpm_data(lpm, i));
|
||||
if (NULL == ref)
|
||||
if (NULL == ref) {
|
||||
delete fcall;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fcall->add_expr(ref);
|
||||
}
|
||||
|
|
@ -195,8 +203,10 @@ static vhdl_expr *array_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm)
|
|||
vhdl_type *atype = new vhdl_type(*adecl->get_type());
|
||||
|
||||
vhdl_expr *select = readable_ref(scope, ivl_lpm_select(lpm));
|
||||
if (NULL == select)
|
||||
if (NULL == select) {
|
||||
delete atype;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vhdl_var_ref *ref = new vhdl_var_ref(renamed, atype);
|
||||
vhdl_type integer(VHDL_TYPE_INTEGER);
|
||||
|
|
|
|||
|
|
@ -313,11 +313,11 @@ void make_assignment(vhdl_procedural *proc, stmt_container *container,
|
|||
if (NULL == test)
|
||||
return;
|
||||
|
||||
vhdl_if_stmt *vhdif = new vhdl_if_stmt(test);
|
||||
|
||||
if (!check_valid_assignment(decl->assignment_type(), proc, stmt))
|
||||
return;
|
||||
|
||||
vhdl_if_stmt *vhdif = new vhdl_if_stmt(test);
|
||||
|
||||
// True part
|
||||
{
|
||||
vhdl_abstract_assign_stmt *a =
|
||||
|
|
@ -1342,6 +1342,7 @@ int draw_casezx(vhdl_procedural *proc, stmt_container *container,
|
|||
"expression labels can be translated to VHDL",
|
||||
ivl_stmt_file(stmt), ivl_stmt_lineno(stmt),
|
||||
(is_casez ? "z" : "x"));
|
||||
delete all;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -153,10 +153,13 @@ static PLI_INT32 sys_fopen_calltf(PLI_BYTE8*name)
|
|||
}
|
||||
|
||||
fname = get_filename(callh, name, fileh);
|
||||
if (fname == 0 && mode) free(mode_string);
|
||||
|
||||
/* If either the mode or file name are not valid just return. */
|
||||
if (fail || fname == 0) return 0;
|
||||
if (fail || fname == 0) {
|
||||
free(fname);
|
||||
if (mode) free(mode_string);
|
||||
return 0;
|
||||
}
|
||||
|
||||
val.format = vpiIntVal;
|
||||
if (mode) {
|
||||
|
|
|
|||
|
|
@ -184,6 +184,7 @@ static PLI_INT32 va_single_argument_compiletf(PLI_BYTE8 *ud)
|
|||
/* Check that there are arguments. */
|
||||
if (argv == 0) {
|
||||
va_error_message(callh, "%s requires one argument.\n", name);
|
||||
free(fun_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -265,6 +266,7 @@ static PLI_INT32 va_double_argument_compiletf(PLI_BYTE8 *ud)
|
|||
/* Check that there are arguments. */
|
||||
if (argv == 0) {
|
||||
va_error_message(callh, "%s requires two arguments.\n", name);
|
||||
free(fun_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -216,6 +216,7 @@ static PLI_INT32 va_single_argument_compiletf(PLI_BYTE8 *ud)
|
|||
/* Check that there are arguments. */
|
||||
if (argv == 0) {
|
||||
va_error_message(callh, "%s requires one argument.\n", name);
|
||||
free(fun_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -303,6 +304,7 @@ static PLI_INT32 va_double_argument_compiletf(PLI_BYTE8 *ud)
|
|||
/* Check that there are arguments. */
|
||||
if (argv == 0) {
|
||||
va_error_message(callh, "%s requires two arguments.\n", name);
|
||||
free(fun_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue