Skip to content

Commit 923d3d3

Browse files
committed
fixed memory leaks and some functions
1 parent fcd8aa2 commit 923d3d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2559
-2438
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# Possible values:
1616
# release
1717
# debug
18-
BUILD_TYPE = release
18+
BUILD_TYPE = debug
1919

2020
#Allows users to pass parameters to cmake
2121
# e.g. make CMAKE_PARAMS="-DVTR_ENABLE_SANITIZE=true"

ODIN_II/SRC/ace.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
2626
#include "cudd.h"
2727
#include "ace.h"
2828
#include "st.h"
29-
#include "allocation_def.h"
29+
3030

3131
#define ACE_P0TO1(P1,PS) ((P1)==0.0)?0.0:(((P1)==1.0)?1.0:0.5*PS/(1.0-(P1)))
3232
#define ACE_P1TO0(P1,PS) ((P1)==0.0)?1.0:(((P1)==0.0)?0.0:0.5*PS/(P1))
@@ -60,7 +60,7 @@ OTHER DEALINGS IN THE SOFTWARE.
6060

6161
typedef unsigned int *pset;
6262

63-
#define ALLOC(type, num) ALLOCATE_ME(num,type)
63+
#define ALLOC(type, num) (type*)calloc(num,sizeof(type))
6464

6565
#define set_remove(set, e) (set[WHICH_WORD(e)] &= ~ (1 << WHICH_BIT(e)))
6666
#define set_insert(set, e) (set[WHICH_WORD(e)] |= 1 << WHICH_BIT(e))
@@ -333,6 +333,8 @@ void compute_switching_activities ( netlist_t *net ) {
333333
}
334334
}
335335
}
336+
Cudd_RecursiveDeref(dd,Cudd_ReadOne(dd));
337+
Cudd_Quit(dd);
336338
}
337339

338340

ODIN_II/SRC/activity_estimation.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ OTHER DEALINGS IN THE SOFTWARE.
3232
#include "ast_util.h"
3333
#include "activity_estimation.h"
3434
#include "netlist_check.h"
35-
#include "allocation_def.h"
35+
3636

3737
#define DEFAULT_STATIC_PROBABILITY .5
3838
#define DEFAULT_TRANSITION_DENSITY .5
@@ -546,20 +546,22 @@ void output_activation_file_ace_and_function_file(char *output_filename, int lut
546546
sprintf(function_file_name, "%s.fun", output_filename);
547547

548548
ace_out = fopen(ace_file_name, "w");
549-
if (ace_out == NULL)
550-
{
549+
if (!ace_out){
551550
error_message(ACTIVATION_ERROR, -1, -1, "Could not open output file %s\n", ace_file_name);
552551
}
552+
free(ace_out);
553+
553554
ac2_out = fopen(ac2_file_name, "w");
554-
if (ac2_out == NULL)
555-
{
555+
if (!ac2_out){
556556
error_message(ACTIVATION_ERROR, -1, -1, "Could not open output file %s\n", ac2_file_name);
557557
}
558+
free(ac2_out);
559+
558560
function_out = fopen(function_file_name, "w");
559-
if (function_out == NULL)
560-
{
561+
if (!function_out){
561562
error_message(ACTIVATION_ERROR, -1, -1, "Could not open output file %s\n", function_file_name);
562563
}
564+
free(function_out);
563565

564566
/* Go through the LUT netlist and print out the ace files */
565567
for (i = 0; i < LUT_netlist->num_forward_levels; i++)

ODIN_II/SRC/activity_estimation.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
21
void activity_estimation(char *input_filename, char *output_filename, int lut_size, netlist_t *LUT_netlist, netlist_t *CLUSTER_netlist);

ODIN_II/SRC/adders.c

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ OTHER DEALINGS IN THE SOFTWARE.
3535
#include "errors.h"
3636
#include "subtractions.h"
3737
#include "print_tags.h"
38-
#include "allocation_def.h"
38+
3939
#include "vtr_list.h"
4040

4141
using vtr::t_linked_vptr;
@@ -155,11 +155,11 @@ void declare_hard_adder(nnode_t *node)
155155
int width_a, width_b, width_sumout;
156156

157157
/* See if this size instance of adder exists? */
158-
if (hard_adders == NULL)
159-
{
158+
if (!hard_adders){
160159
printf(ERRTAG "Instantiating adder where adders do not exist\n");
161160
}
162161
tmp = (t_adder *)hard_adders->instances;
162+
163163
width_a = node->input_port_sizes[0];
164164
width_b = node->input_port_sizes[1];
165165
width_sumout = node->output_port_sizes[1];
@@ -189,33 +189,18 @@ void declare_hard_adder(nnode_t *node)
189189
*-------------------------------------------------------------------------*/
190190
void instantiate_hard_adder(nnode_t *node, short mark, netlist_t * /*netlist*/)
191191
{
192-
char *new_name;
193-
int len, sanity, i;
194-
192+
int i;
195193
declare_hard_adder(node);
196194

197-
/* Need to give node proper name */
198-
/* 20 chars should hold mul specs */
199-
new_name = (char*)calloc(strlen(node->name)+20,sizeof(char));
200-
201-
/* wide input first :) */
202-
if (node->input_port_sizes[0] > node->input_port_sizes[1])
203-
sanity = sprintf(new_name, "%s", node->name);
204-
else
205-
sanity = sprintf(new_name, "%s", node->name);
206-
207-
if (strlen(node->name)+20 <= sanity) /* buffer not large enough */
208-
oassert(FALSE);
209-
210195
/* Give names to the output pins */
211196
for (i = 0; i < node->num_output_pins; i++)
212197
{
213-
if (node->output_pins[i]->name == NULL)
214-
{
215-
new_name = (char*)calloc(strlen(node->name) + 20,sizeof(char));
216-
sprintf(new_name, "%s[%d]", node->name, node->output_pins[i]->pin_node_idx);
217-
node->output_pins[i]->name = new_name;
198+
if (node->output_pins[i]->name){
199+
free(node->output_pins[i]->name);
218200
}
201+
size_t length = snprintf(NULL,0,"%s[%d]", node->name, node->output_pins[i]->pin_node_idx);
202+
node->output_pins[i]->name = (char*)calloc(length +1,sizeof(char));
203+
sprintf(node->output_pins[i]->name, "%s[%d]", node->name, node->output_pins[i]->pin_node_idx);
219204
}
220205

221206
node->traverse_visited = mark;
@@ -718,7 +703,8 @@ void split_adder(nnode_t *nodeo, int a, int b, int sizea, int sizeb, int cin, in
718703

719704
for(i = 0; i < count; i++)
720705
{
721-
node[i] = allocate_nnode();
706+
node[i] = (nnode_t *)my_malloc_struct(sizeof(nnode_t));
707+
allocate_nnode(node[i]);
722708
node[i]->name = (char *)calloc(strlen(nodeo->name) + 20,sizeof(char));
723709
sprintf(node[i]->name, "%s-%d", nodeo->name, i);
724710
if(i == count - 1)
@@ -774,7 +760,9 @@ void split_adder(nnode_t *nodeo, int a, int b, int sizea, int sizeb, int cin, in
774760
connect_nodes(netlist->gnd_node, 0, node[0], 0);
775761
connect_nodes(netlist->gnd_node, 0, node[0], sizea);
776762
//hang the first sumout
777-
node[0]->output_pins[1] = allocate_npin();
763+
764+
node[0]->output_pins[1] = (npin_t *)my_malloc_struct(sizeof(npin_t));
765+
allocate_npin(node[0]->output_pins[1]);
778766
node[0]->output_pins[1]->name = append_string("", "%s~dummy_output~%d~%d", node[0]->name, 0, 1);
779767
}
780768

@@ -824,11 +812,13 @@ void split_adder(nnode_t *nodeo, int a, int b, int sizea, int sizeb, int cin, in
824812
remap_pin_to_new_node(nodeo->output_pins[j], node[0], j + 2);
825813
else
826814
{
827-
node[0]->output_pins[j + 2] = allocate_npin();
815+
node[0]->output_pins[j + 2] = (npin_t *)my_malloc_struct(sizeof(npin_t));
816+
allocate_npin(node[0]->output_pins[j + 2]);
828817
node[0]->output_pins[j + 2]->name = append_string("", "%s~dummy_output~%d~%d", node[0]->name, 0, j + 2);
829818
}
830819
//hang the first cout
831-
node[0]->output_pins[0] = allocate_npin();
820+
node[0]->output_pins[0] = (npin_t *)my_malloc_struct(sizeof(npin_t));
821+
allocate_npin(node[0]->output_pins[0]);
832822
node[0]->output_pins[0]->name = append_string("", "%s~dummy_output~%d~%d", node[0]->name, 0, 0);
833823
}
834824
}
@@ -858,13 +848,15 @@ void split_adder(nnode_t *nodeo, int a, int b, int sizea, int sizeb, int cin, in
858848
remap_pin_to_new_node(nodeo->output_pins[(count - 1) * sizea + j - 1], node[count - 1], j + 1);
859849
else
860850
{
861-
node[count - 1]->output_pins[j + 1] = allocate_npin();
851+
node[count - 1]->output_pins[j + 1] = (npin_t *)my_malloc_struct(sizeof(npin_t));
852+
allocate_npin(node[count - 1]->output_pins[j + 1]);
862853
// Pad outputs with a unique and descriptive name to avoid collisions.
863854
node[count - 1]->output_pins[j + 1]->name = append_string("", "%s~dummy_output~%d~%d", node[count - 1]->name, count - 1, j + 1);
864855
}
865856
}
866857
//Hang the last cout
867-
node[count - 1]->output_pins[0] = allocate_npin();
858+
node[count - 1]->output_pins[0] = (npin_t *)my_malloc_struct(sizeof(npin_t));
859+
allocate_npin(node[count - 1]->output_pins[0]);
868860
// Pad outputs with a unique and descriptive name to avoid collisions.
869861
node[count - 1]->output_pins[0]->name = append_string("", "%s~dummy_output~%d~%d", node[count - 1]->name, count - 1, 0);
870862
}
@@ -877,7 +869,8 @@ void split_adder(nnode_t *nodeo, int a, int b, int sizea, int sizeb, int cin, in
877869
remap_pin_to_new_node(nodeo->output_pins[nodeo->num_output_pins - 1], node[count - 1], 0);
878870
else
879871
{
880-
node[count - 1]->output_pins[0] = allocate_npin();
872+
node[count - 1]->output_pins[0] = (npin_t *)my_malloc_struct(sizeof(npin_t));
873+
allocate_npin(node[count - 1]->output_pins[0]);
881874
// Pad outputs with a unique and descriptive name to avoid collisions.
882875
node[count - 1]->output_pins[0]->name = append_string("", "%s~dummy_output~%d~%d", node[count - 1]->name, count - 1, 0);
883876
}

ODIN_II/SRC/allocation_def.h

Lines changed: 0 additions & 4 deletions
This file was deleted.

ODIN_II/SRC/ast_elaborate.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ OTHER DEALINGS IN THE SOFTWARE.
3333
#include "verilog_bison.h"
3434
#include "netlist_create_from_ast.h"
3535
#include "ctype.h"
36-
#include "allocation_def.h"
36+
3737

3838
#define read_node 1
3939
#define write_node 2
@@ -116,8 +116,13 @@ void optimize_for_tree()
116116
}
117117
temp_parent_node = (ast_node_t*)calloc(1,sizeof(ast_node_t));
118118
oassert(list_for_node[j]->children[0]->children[0]->types.identifier);
119+
120+
if(v_name){
121+
free(v_name);
122+
}
119123
v_name = (char*)calloc(strlen(list_for_node[j]->children[0]->children[0]->types.identifier)+1,sizeof(char));
120124
sprintf(v_name, "%s", list_for_node[j]->children[0]->children[0]->types.identifier);
125+
121126
initial = list_for_node[j]->children[0]->children[1]->types.number.value;
122127
v_value = initial;
123128
terminal = list_for_node[j]->children[1]->children[1]->types.number.value;
@@ -130,7 +135,7 @@ void optimize_for_tree()
130135
T = (ast_node_t*)calloc(1,sizeof(ast_node_t));
131136
copy_tree((list_for_node[j])->children[3], T);
132137
add_child_to_node(temp_parent_node, T);
133-
value_string = (char*)calloc(1,sizeof(int));
138+
value_string = (char*)calloc(sizeof(long long)*8+1,sizeof(char));
134139
sprintf(value_string, "%lld", v_value);
135140
modify_expression(expression, infix_expression, value_string);
136141
translate_expression(infix_expression, postfix_expression);
@@ -678,7 +683,7 @@ void remove_intermediate_variable(ast_node_t *node, char list[10][20])
678683
{
679684
for (j = 0; j < count_write; j++)
680685
{
681-
temp = (char*)calloc(20,sizeof(char));
686+
temp = (char*)calloc(strlen(list[j])+1,sizeof(char));
682687
new_node = (ast_node_t *)calloc(1,sizeof(ast_node_t));
683688
sprintf(temp, "%s", list[j]);
684689
search_marked_node(node->children[i], 2, temp, &write); //search for "write" nodes
@@ -1360,7 +1365,6 @@ void delete_continuous_multiply(int *build)
13601365
void create_ast_node(enode *temp, ast_node_t *node, int line_num, int file_num)
13611366
{
13621367
char num[12] = {0};
1363-
int len;
13641368

13651369
switch(temp->flag)
13661370
{
@@ -1375,7 +1379,6 @@ void create_ast_node(enode *temp, ast_node_t *node, int line_num, int file_num)
13751379
break;
13761380

13771381
case 3:
1378-
len = strlen(temp->type.variable);
13791382
initial_node(node, IDENTIFIERS, line_num, file_num);
13801383
node->types.identifier = (char*)calloc(strlen(temp->type.variable)+1,sizeof(char));
13811384
strcpy(node->types.identifier, temp->type.variable);

ODIN_II/SRC/ast_elaborate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2121
OTHER DEALINGS IN THE SOFTWARE.
2222
*/
2323

24+
2425
int simplify_ast();
2526
void optimize_for_tree();
2627
void search_for_node(ast_node_t *root, ast_node_t *list_for_node[], ast_node_t *list_parent[]);

ODIN_II/SRC/ast_optimizations.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ OTHER DEALINGS IN THE SOFTWARE.
2828
#include "ast_optimizations.h"
2929
#include "parse_making_ast.h"
3030
#include "verilog_bison.h"
31-
#include "allocation_def.h"
31+
3232

3333
/* --------------------------------------------------------------------------------------------
3434
--------------------------------------------------------------------------------------------

ODIN_II/SRC/ast_optimizations.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11

2-
32
void optimizations_on_AST(ast_node_t *top);
43
info_ast_visit_t *constantFold(ast_node_t *node);

ODIN_II/SRC/ast_util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ OTHER DEALINGS IN THE SOFTWARE.
3434
#include "ast_util.h"
3535
#include "odin_util.h"
3636
#include "ast_optimizations.h"
37-
#include "allocation_def.h"
37+
3838

3939
char **get_name_of_pins_number(ast_node_t *var_node, int start, int width);
4040

@@ -491,7 +491,7 @@ void make_concat_into_list_of_strings(ast_node_t *concat_top, char *instance_nam
491491
}
492492
}
493493
else {
494-
error_message(NETLIST_ERROR, concat_top->line_number, concat_top->file_number, "Missssing declaration of this symbol %s\n", temp_string);
494+
error_message(NETLIST_ERROR, concat_top->line_number, concat_top->file_number, "Missssing declaration of this symbol %s\n", temp_string);
495495
}
496496
}
497497
else if (concat_top->children[i]->type == ARRAY_REF)

ODIN_II/SRC/ast_util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
12
#include "types.h"
23

4+
35
ast_node_t* create_node_w_type(ids id, int line_number, int file_number);
46
void free_child_in_tree(ast_node_t *from, int idx_removal);
57
void free_ast_node(ast_node_t *child);

ODIN_II/SRC/config_type.h

Lines changed: 0 additions & 41 deletions
This file was deleted.

ODIN_II/SRC/globals.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,3 @@ extern int file_line_number;
5656

5757
#endif
5858

59-

ODIN_II/SRC/hard_blocks.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2121
OTHER DEALINGS IN THE SOFTWARE.
2222
*/
2323

24-
25-
2624
#include <stdlib.h>
2725
#include <stdio.h>
2826
#include <string.h>

ODIN_II/SRC/hard_blocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
2626

2727
#include "types.h"
2828

29+
2930
extern STRING_CACHE *hard_block_names;
3031

3132
extern void register_hard_blocks();

ODIN_II/SRC/hashtable.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2020
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2121
OTHER DEALINGS IN THE SOFTWARE.
2222
*/
23+
2324
#include <string.h>
2425
#include <stdio.h>
2526
#include <stdlib.h>
2627
#include "hashtable.h"
2728
#include "types.h"
28-
#include "allocation_def.h"
29+
30+
2931

3032
void ___hashtable_add (hashtable_t *h, const void *key, size_t key_length, void *item);
3133
void* ___hashtable_remove (hashtable_t *h, const void *key, size_t key_length);

0 commit comments

Comments
 (0)