Skip to content

Commit

Permalink
- fix memory leak (unfreed temp space)
Browse files Browse the repository at this point in the history
- removed unnecessary memset() where array is initialized directly afterwards

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14339 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Henning Kiel committed Dec 12, 2012
1 parent 56fb09c commit 0678291
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 22 deletions.
28 changes: 14 additions & 14 deletions Compiler/runtime/BackendDAEEXT.cpp
Expand Up @@ -76,7 +76,7 @@ void BackendDAEEXTImpl__initMarks(int nvars, int neqns)
// Why are the inputs not even used?
v_mark.clear();
e_mark.clear();
}
}

void BackendDAEEXTImpl__eMark(int i)
{
Expand Down Expand Up @@ -143,23 +143,23 @@ void BackendDAEEXTImpl__initLowLink(int nvars)
{
//cout << "init lowlink n= " << nvars << endl;
lowlink.reserve(nvars);

while (lowlink.size() < (unsigned int)nvars)
lowlink.push_back(0);
for (int i =0; i < nvars; i++)
lowlink[i]=0;
}
}

void BackendDAEEXTImpl__initNumber(int nvars)
{
//cout << "init number n= " << nvars << endl;
number.reserve(nvars);

while (number.size() < (unsigned int)nvars)
number.push_back(0);
for (int i =0; i < nvars; i++)
for (int i =0; i < nvars; i++)
number[i]=0;
}
}

void BackendDAEEXTImpl__setLowLink(int i, int val)
{
Expand Down Expand Up @@ -234,31 +234,31 @@ void BackendDAEExtImpl__matching(int nvars, int neqns, int matchingID, int cheap
int i=0;
if (clear_match==0){
if (neqns>n) {
int* tmp = (int*) malloc(neqns * sizeof(int));
if(match)
{
int* tmp = (int*) malloc(neqns * sizeof(int));
memcpy(tmp,match,n*sizeof(int));
free(match);
match = tmp;
for (i = n; i < neqns; i++) {
match[i] = -1;
}
for (i = n; i < neqns; i++) {
match[i] = -1;
}
} else {
match = (int*) malloc(neqns * sizeof(int));
memset(match,-1,neqns * sizeof(int));
}
n = neqns;
}
if (nvars>m) {
int* tmp = (int*) malloc(nvars * sizeof(int));
if(row_match)
{
int* tmp = (int*) malloc(nvars * sizeof(int));
memcpy(tmp,row_match,m*sizeof(int));
free(row_match);
row_match = tmp;
for (i = m; i < nvars; i++) {
row_match[i] = -1;
}
for (i = m; i < nvars; i++) {
row_match[i] = -1;
}
} else {
row_match = (int*) malloc(nvars * sizeof(int));
memset(row_match,-1,nvars * sizeof(int));
Expand Down
2 changes: 0 additions & 2 deletions Compiler/runtime/BackendDAEEXT_omc.cpp
Expand Up @@ -176,7 +176,6 @@ extern int BackendDAEEXT_setAssignment(int lenass1, int lenass2, modelica_metaty
free(match);
}
match = (int*) malloc(n * sizeof(int));
memset(match,-1,n * sizeof(int));
for(i=0; i<n; ++i) {
match[i] = MMC_UNTAGFIXNUM(MMC_STRUCTDATA(ass1)[i])-1;
if (match[i]<0) match[i] = -1;
Expand All @@ -191,7 +190,6 @@ extern int BackendDAEEXT_setAssignment(int lenass1, int lenass2, modelica_metaty
free(row_match);
}
row_match = (int*) malloc(m * sizeof(int));
memset(row_match,-1,m * sizeof(int));
for(i=0; i<m; ++i) {
row_match[i] = MMC_UNTAGFIXNUM(MMC_STRUCTDATA(ass2)[i])-1;
if (row_match[i]<0) row_match[i] = -1;
Expand Down
2 changes: 0 additions & 2 deletions Compiler/runtime/BackendDAEEXT_rml.cpp
Expand Up @@ -333,7 +333,6 @@ RML_BEGIN_LABEL(BackendDAEEXT__setAssignment)
free(match);
}
match = (int*) malloc(n * sizeof(int));
memset(match,-1,n * sizeof(int));
for(i=0; i<n; ++i) {
match[i] = RML_UNTAGFIXNUM(RML_STRUCTDATA(rmlA2)[i])-1;
if (match[i]<0) match[i] = -1;
Expand All @@ -346,7 +345,6 @@ RML_BEGIN_LABEL(BackendDAEEXT__setAssignment)
free(row_match);
}
row_match = (int*) malloc(m * sizeof(int));
memset(row_match,-1,m * sizeof(int));
for(i=0; i<m; ++i) {
row_match[i] = RML_UNTAGFIXNUM(RML_STRUCTDATA(rmlA3)[i])-1;
if (row_match[i]<0) row_match[i] = -1;
Expand Down
4 changes: 0 additions & 4 deletions Compiler/runtime/matching_cheap.c
Expand Up @@ -50,7 +50,6 @@ void sk_cheap(int* col_ptrs, int* col_ids, int* row_ptrs, int* row_ids,

int* col_stack = (int*)malloc(n * sizeof(int));
int* col_degrees = (int*)malloc(n * sizeof(int));
memset(col_degrees, 0, n * sizeof(int));

int no_of_d1_cols = 0;
for(i = 0; i < n; i++) {
Expand All @@ -62,7 +61,6 @@ void sk_cheap(int* col_ptrs, int* col_ids, int* row_ptrs, int* row_ids,

int* row_stack = (int*)malloc(m * sizeof(int));
int* row_degrees = (int*)malloc(m * sizeof(int));
memset(row_degrees, 0, m * sizeof(int));

int no_of_d1_rows = 0;
for(i = 0; i < m; i++) {
Expand Down Expand Up @@ -204,7 +202,6 @@ void sk_cheap_rand(int* col_ptrs, int* col_ids, int* row_ptrs, int* row_ids,
srand(1);
int* col_stack = (int*)malloc(n * sizeof(int));
int* col_degrees = (int*)malloc(n * sizeof(int));
memset(col_degrees, 0, n * sizeof(int));

int no_of_d1_cols = 0;
for(i = 0; i < n; i++) {
Expand All @@ -216,7 +213,6 @@ void sk_cheap_rand(int* col_ptrs, int* col_ids, int* row_ptrs, int* row_ids,

int* row_stack = (int*)malloc(m * sizeof(int));
int* row_degrees = (int*)malloc(m * sizeof(int));
memset(row_degrees, 0, m * sizeof(int));

int no_of_d1_rows = 0;
for(i = 0; i < m; i++) {
Expand Down

0 comments on commit 0678291

Please sign in to comment.