Skip to content

Commit 5dbdb9f

Browse files
committed
[Libs]: remove heap allocation for t_arch data structure in read_arch and write_arch_bb to avoid memory leaks
Signd-off-by: Seyed Alireza Damghani <[email protected]>
1 parent 24eb704 commit 5dbdb9f

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

libs/libarchfpga/src/main.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void print_help();
2020

2121
int main(int argc, char** argv) {
2222
try {
23-
t_arch* arch = (t_arch*)vtr::calloc(1, sizeof(t_arch));
23+
t_arch arch;
2424
std::vector<t_physical_tile_type> physical_tile_types;
2525
std::vector<t_logical_block_type> logical_block_types;
2626

@@ -44,15 +44,14 @@ int main(int argc, char** argv) {
4444
printf("Reading in architecture\n");
4545

4646
/* function declarations */
47-
XmlReadArch(argv[1], atoi(argv[2]), arch, physical_tile_types, logical_block_types);
47+
XmlReadArch(argv[1], atoi(argv[2]), &arch, physical_tile_types, logical_block_types);
4848

4949
printf("Printing Results\n");
5050

51-
EchoArch(argv[3], physical_tile_types, logical_block_types, arch);
51+
EchoArch(argv[3], physical_tile_types, logical_block_types, &arch);
5252

5353
// CLEAN UP
54-
free_arch(arch);
55-
vtr::free(arch);
54+
free_arch(&arch);
5655
free_type_descriptors(physical_tile_types);
5756
free_type_descriptors(logical_block_types);
5857

libs/libarchfpga/src/write_arch_bb.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void print_help();
2121

2222
int main(int argc, char** argv) {
2323
try {
24-
t_arch* arch = (t_arch*)vtr::calloc(1, sizeof(t_arch));
24+
t_arch arch;
2525
std::vector<t_physical_tile_type> physical_tile_types;
2626
std::vector<t_logical_block_type> logical_block_types;
2727

@@ -44,15 +44,14 @@ int main(int argc, char** argv) {
4444
printf("Reading in architecture ...\n");
4545

4646
/* function declarations */
47-
XmlReadArch(argv[1], false, arch, physical_tile_types, logical_block_types);
47+
XmlReadArch(argv[1], false, &arch, physical_tile_types, logical_block_types);
4848

4949
printf("Printing Results ...\n");
5050

51-
WriteModels_bb(argv[1], argv[2], arch);
51+
WriteModels_bb(argv[1], argv[2], &arch);
5252

5353
// CLEAN UP
54-
free_arch(arch);
55-
vtr::free(arch);
54+
free_arch(&arch);
5655
free_type_descriptors(physical_tile_types);
5756
free_type_descriptors(logical_block_types);
5857

0 commit comments

Comments
 (0)